Link Preview Module¶
Build-time preview payloads and static asset helpers for same-site link preview.
Called from plugin core when preview_config.enabled is true. Link path normalization is shared with the graph via mkdocs_note.utils.links.
Same-site link hover preview: build-time JSON and static asset helpers.
See issue #82. Opt-in via preview_config.enabled; when disabled the plugin must not register assets, inject scripts, or write previews.json.
PreviewBuilder ¶
Build previews.json payloads from documentation pages.
Source code in src/mkdocs_note/preview.py
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | |
__call__(files) ¶
Scan files and return the preview mapping.
Source code in src/mkdocs_note/preview.py
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | |
add_preview_static_resources(config) ¶
Register preview JS/CSS on the MkDocs config (call only when enabled).
Source code in src/mkdocs_note/preview.py
883 884 885 886 887 888 | |
copy_preview_static_assets(static_dir, config) ¶
Copy preview.js / preview.css into the site directory.
Source code in src/mkdocs_note/preview.py
914 915 916 917 918 919 920 921 922 | |
create_preview_markdown(markdown_extensions=None, mdx_configs=None) ¶
Create a Python-Markdown instance aligned with the site config.
Loads extensions incrementally so one broken/plugin-only extension cannot force a full fallback to the basic set.
Source code in src/mkdocs_note/preview.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
decode_fragment(fragment) ¶
Normalize a URL fragment to decoded Unicode (no leading #).
Source code in src/mkdocs_note/preview.py
674 675 676 677 678 679 680 681 682 | |
excerpt_html(section_md, page_url, site_base, *, md=None, markdown_extensions=None, mdx_configs=None, source_file=None, files=None) ¶
Build a sanitized rich HTML excerpt from section markdown.
When md or site extension config is provided, rendering follows the MkDocs/Material markdown stack (minus unsafe/noisy extensions).
Source code in src/mkdocs_note/preview.py
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
excerpt_plain(section_md, max_chars) ¶
Plain-text excerpt: prose + fenced code as text, truncated.
Source code in src/mkdocs_note/preview.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
extract_summary(meta, body, max_chars) ¶
Summary priority: frontmatter description → summary → first paragraph.
Source code in src/mkdocs_note/preview.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
extract_title_from_page(meta, body, fallback) ¶
Resolve a display title from frontmatter, first H1, or fallback.
Source code in src/mkdocs_note/preview.py
144 145 146 147 148 149 150 151 152 153 154 155 156 | |
first_prose_paragraph(body, max_chars) ¶
Extract the first non-empty prose paragraph from markdown body.
Skips ATX headings, blockquotes, tables, lists, and Material admonition / details / tab markers (!!!, ???, ===) plus their indented bodies.
Source code in src/mkdocs_note/preview.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
inject_preview_script(output, config, preview_config, *, graph_enabled=False) ¶
Inject window.preview_options before </body>.
Source code in src/mkdocs_note/preview.py
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 | |
prepare_preview_markdown_config(markdown_extensions=None, mdx_configs=None) ¶
Filter site markdown extensions for hover-preview rendering.
Reuses the MkDocs/Material extension stack where practical, but drops toc (permalink clutter), pymdownx.snippets (arbitrary includes), and plugin-only extensions such as mkdocstrings.
Source code in src/mkdocs_note/preview.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
resolve_section_markdown(sections, frag) ¶
Return (heading_text, section_md) for a fragment.
If the section has no extractable prose, descend into the first nested child with content; otherwise return the hierarchical section body (which already includes nested headings when split with same-or-higher rules).
Source code in src/mkdocs_note/preview.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
sanitize_preview_html(raw) ¶
Sanitize HTML to the preview allow-list.
Source code in src/mkdocs_note/preview.py
631 632 633 634 635 636 637 638 639 | |
slugify_heading(text) ¶
Slugify a heading title to match Material / pymdownx TOC ids.
Source code in src/mkdocs_note/preview.py
59 60 61 62 | |
strip_markdown_inline(text) ¶
Remove common inline markdown markers for plain-text summaries.
Source code in src/mkdocs_note/preview.py
65 66 67 68 69 70 71 72 73 | |
write_previews_file(data, config) ¶
Write site/previews/previews.json.
Source code in src/mkdocs_note/preview.py
925 926 927 928 929 930 931 932 933 934 935 | |