Skip to content

Commit

Permalink
Convert source to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Oct 20, 2021
1 parent 9d4971f commit de27d69
Show file tree
Hide file tree
Showing 44 changed files with 3,228 additions and 3,506 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -69,7 +69,7 @@ $ cat hello.html
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
document.getElementById('content').innerHTML =
marked('# Marked in the browser\n\nRendered by **marked**.');
marked.parse('# Marked in the browser\n\nRendered by **marked**.');
</script>
</body>
</html>
Expand Down
12 changes: 7 additions & 5 deletions build-docs.js
@@ -1,8 +1,10 @@
const { mkdir, rmdir, readdir, stat, readFile, writeFile, copyFile } = require('fs').promises;
const { join, dirname, parse, format } = require('path');
const marked = require('./');
const { highlight, highlightAuto } = require('highlight.js');
const titleize = require('titleize');
import { promises } from 'fs';
import { join, dirname, parse, format } from 'path';
import { parse as marked } from './lib/marked.esm.js';
import { HighlightJS } from 'highlight.js';
import titleize from 'titleize';
const { mkdir, rmdir, readdir, stat, readFile, writeFile, copyFile } = promises;
const { highlight, highlightAuto } = HighlightJS;
const cwd = process.cwd();
const inputDir = join(cwd, 'docs');
const outputDir = join(cwd, 'public');
Expand Down
6 changes: 3 additions & 3 deletions docs/INDEX.md
Expand Up @@ -56,7 +56,7 @@ $ marked -s "*hello world*"
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
document.getElementById('content').innerHTML =
marked('# Marked in browser\n\nRendered by **marked**.');
marked.parse('# Marked in browser\n\nRendered by **marked**.');
</script>
</body>
</html>
Expand All @@ -65,8 +65,8 @@ $ marked -s "*hello world*"
**Node.js**

```js
const marked = require("marked");
const html = marked('# Marked in Node.js\n\nRendered by **marked**.');
const { parse } = require("marked");
const html = parse('# Marked in Node.js\n\nRendered by **marked**.');
```


Expand Down
15 changes: 8 additions & 7 deletions docs/USING_ADVANCED.md
@@ -1,7 +1,8 @@
## The `marked` function
## The `parse` function

```js
marked(markdownString [,options] [,callback])
const { parse } = require('marked');
parse(markdownString [,options] [,callback])
```

|Argument |Type |Notes |
Expand Down Expand Up @@ -36,7 +37,7 @@ marked.setOptions({
});

// Compile
console.log(marked(markdownString));
console.log(marked.parse(markdownString));
```

<h2 id="options">Options</h2>
Expand Down Expand Up @@ -67,7 +68,7 @@ console.log(marked(markdownString));
You can parse inline markdown by running markdown through `marked.parseInline`.

```js
const blockHtml = marked('**strong** _em_');
const blockHtml = marked.parse('**strong** _em_');
console.log(blockHtml); // '<p><strong>strong</strong> <em>em</em></p>'

const inlineHtml = marked.parseInline('**strong** _em_');
Expand All @@ -87,7 +88,7 @@ marked.setOptions({
}
});

marked(markdownString, (err, html) => {
marked.parse(markdownString, (err, html) => {
console.log(html);
});
```
Expand All @@ -109,7 +110,7 @@ const marked = require('marked');
const { parentPort } = require('worker_threads');

parentPort.on('message', (markdownString) => {
parentPort.postMessage(marked(markdownString));
parentPort.postMessage(marked.parse(markdownString));
});
```

Expand Down Expand Up @@ -144,7 +145,7 @@ importScripts('path/to/marked.min.js');

onmessage = (e) => {
const markdownString = e.data
postMessage(marked(markdownString));
postMessage(marked.parse(markdownString));
};
```

Expand Down
8 changes: 4 additions & 4 deletions docs/USING_PRO.md
Expand Up @@ -89,7 +89,7 @@ const renderer = {
marked.use({ renderer });

// Run marked
console.log(marked('# heading+'));
console.log(marked.parse('# heading+'));
```

**Output:**
Expand Down Expand Up @@ -195,7 +195,7 @@ const tokenizer = {
marked.use({ tokenizer });

// Run marked
console.log(marked('$ latex code $\n\n` other code `'));
console.log(marked.parse('$ latex code $\n\n` other code `'));
```

**Output:**
Expand Down Expand Up @@ -276,7 +276,7 @@ const walkTokens = (token) => {
marked.use({ walkTokens });

// Run marked
console.log(marked('# heading 2\n\n## heading 3'));
console.log(marked.parse('# heading 2\n\n## heading 3'));
```

**Output:**
Expand Down Expand Up @@ -420,7 +420,7 @@ marked.use({ extensions: [descriptionlist, description] });
marked.use({extensions: [descriptionList] });
marked.use({extensions: [description] });

console.log(marked('A Description List:\n'
console.log(marked.parse('A Description List:\n'
+ ': Topic 1 : Description 1\n'
+ ': **Topic 2** : *Description 2*'));
```
Expand Down
1 change: 0 additions & 1 deletion index.js

This file was deleted.

1 change: 1 addition & 0 deletions jasmine.json
Expand Up @@ -6,6 +6,7 @@
"helpers": [
"helpers/helpers.js"
],
"jsLoader": "import",
"stopSpecOnExpectationFailure": false,
"random": true
}

0 comments on commit de27d69

Please sign in to comment.