@4dsas/doc_preprocessing

Preprocess 4D doc to be built by docusaurus

Usage no npm install needed!

<script type="module">
  import 4dsasDocPreprocessing from 'https://cdn.skypack.dev/@4dsas/doc_preprocessing';
</script>

README

doc_preprocessing

This library helps the markdown writers by adding invisible commands in markdown. Have the possibility to "include" and "ref" any markdown part with invisible commands.

This package can be added in the current project by adding "@4dsas/doc_preprocessing": "^1.0.5" in the package.json It adds special command to help writing markdown All commands will disappear during the preprocess.

Reference and Include

The commands "Reference" and "Include" enables to duplicate markdown

Reference

The command is REF. It is used as:

<!-- REF nameOfReference-->content<!-- END REF -->

with:

  • nameOfReference: is the name of the reference it should be unique
  • content: is any content you wish it includes break lines.

Example:

# Title
<!-- REF reference-->Ref1<!-- END REF-->

The preprocess will remove all commands

Before:

# Title
<!-- REF reference1 -->Ref1<!-- END REF--> *TEST*
<!-- REF reference2 -->Ref2
<!-- END REF-->
<!-- REF reference3 -->
Ref3
<!-- END REF-->

After:

# Title
Ref1 *TEST*
Ref2

Ref3

A reference is generally paired with an include

Include

The command is INCLUDE . It is used as:

<!-- INCLUDE nameOfReference-->

with:

  • nameOfReference: is the name of the reference created by @REF@

Before:

# Title
<!-- REF reference1 -->Ref1<!-- END REF--> *TEST*
<!-- REF reference2 -->Ref2
<!-- END REF-->
<!-- REF reference3 -->
BEFORE <!-- INCLUDE reference1 --> TEST INCLUDE
Ref3
<!-- END REF-->

After:

# Title
Ref1 *TEST*
Ref2

Ref3
BEFORE Ref1 TEST INCLUDE

The reference and include does not have a location restriction, it will work with any markdown file.

How it works?

A first pass will find all the REFERENCE and store them. A reference is stored with it's ID, the file path. But also the start and end index.

A second pass will replace all the INCLUDE by its reference if found. Moreover all the markdown comments will be cleaned up if they are not recognised.

A log message is displayed for any error found.

The program will only search inside ".mk" files, the other files are untouched or copied to the new destination depending on their last modification date.