Skip to main content

Adding partial blocks, segments for resue.

Importing and inserting other Markdown files is an MDX feature that Docusaurus supports. It allows reusing existing content in other files.

It follows a strict naming scheme and will always import the complete content.

  • The file should start with the _markdown- prefix, e.g. _markdown-partial-segment.md

    • The _-prefix markes it as a partial 'hidden' document and will no longer show up in the sidebar. This is the default Docusaurus behavior.
    • The prefix addition markdown allows the importer to safely identify it as a Markdown (.md) file.
      • In can be ommitted but it is part of the naming convetion.
    • The remaining part of the name should be lowercased and separated with - for multiple words.
    My partial segment from `_markdown-partial-segment.md`
  • Add an import-statement into another .md file that will be extended and add the section as HTML tag/element to the desired position.

    ---
    sidebar_position: 0
    title: My actual help document
    ---

    <!-- import partial segment -->
    import PartialSegment from './resources/_markdown-partial-segment.md';

    Some content...

    <!-- place partial segment -->
    <PartialSegment/>

    More content...

    • The name PartialSegment of the element in the import statmenet is user defined.

      • The name must be unique in the importing file.
      • It defines the name of the HTML tag used for placement.
    • The Path './resources/_markdown-partial-segment.md' of the import must be a relative path leading to the segment file, just like when importing images.

      • In the example it is asumed that the importing dcocument resides in the parent folder.
    • Place an HTML tag with the same name (e.g. <PartialSegment/>) as in the import somewhere after import statement within the markdoen file.

    • The default editor does not highlight the import syntax.