Skip to content

Commit

Permalink
Merge pull request #6 from revdavethompson/4-includes-inside-markdown
Browse files Browse the repository at this point in the history
4 includes inside markdown
  • Loading branch information
worlduniting authored Mar 13, 2023
2 parents 4b12d6a + e9e53de commit 8641cf4
Show file tree
Hide file tree
Showing 14 changed files with 4,563 additions and 912 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Licensed under the standard MIT license:

Copyright 2023 World Uniting International.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Empty file removed WUI-LICENSE
Empty file.
3 changes: 1 addition & 2 deletions book.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
isbn: 9023890424159
toc: true
files:
- index.md
- more-content.md
- index.md
14 changes: 10 additions & 4 deletions build/html/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<html>
<body>
<h1>My Newest Document</h1>
<p>Here is some content for you.</p>
<h1>My Test Document</h1>
<p>Here is some content.</p>
<h2>More Content</h2>
<p>This is some more content.</p>
<h2>Sub Content</h2>
<p>This is even more content.</p>
<h2>Nested Content</h2>
<p>This is some nested content.</p>
<h3>GFM Example</h3>
<pre><code class="language-javascript"> function () {
this is a function
}
// Here's a comment
</code></pre>
<h2>More Content</h2>
<p>This is some more content.</p>
<p>the close</p>
</body>
</html>
12 changes: 9 additions & 3 deletions lib/convertGfmToHtml.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkHtml from 'remark-html';
import remarkGfm from 'remark-gfm';
import includerjs from '@worlduniting/includerjs';
import yaml from 'js-yaml';

// Define __dirname for ES module - so we can use it like CommonJS
Expand All @@ -30,19 +31,24 @@ export default function convertGfmToHtml() {
const markdownDocument = files
.map(file => fs.readFileSync(path.join(manuscriptDir, file), 'utf8'))
.join('\n\n');

// Process @include statements using the includer module
const processedMarkdown = includerjs(markdownDocument, { basePath: manuscriptDir });

// Convert the markdown document to HTML using Remark
const html = unified()
// convert markdown to a MD-AST syntax tree
.use(remarkParse)
// convert md-ast to gfm-ast
.use(remarkGfm)
// convert gfm-ast to html-ast
// but don't git rid of none-markdown syntax (sanitize)
// but don't git rid of none-markdown syntax
.use(remarkHtml, { sanitize: false, handlers: {} })
.processSync(markdownDocument)
.processSync(processedMarkdown)
.toString();

// Write the HTML output to the output file
fs.writeFileSync(outputFile, html);

console.log(`HTML file written to ${outputFile}`);
}
}
4 changes: 4 additions & 0 deletions manuscript/close.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
the close

</body>
</html>
Loading

0 comments on commit 8641cf4

Please sign in to comment.