Skip to content

Commit

Permalink
Default to GitHub Flavored Markdown
Browse files Browse the repository at this point in the history
- Configure Turndown for GFM per [docs][1]
- Use [a fork of turndown-plugin-gfm][2] due to [issues with the
  original turndown-plugin-gfm][3]
- Remove custom strikethrough logic which is now redundant due to GFM
  plugin

[1]: https://github.com/domchristie/turndown#usepluginarray
[2]: https://www.npmjs.com/package/joplin-turndown-plugin-gfm
[3]: mixmark-io/turndown-plugin-gfm#3
  • Loading branch information
sh78 committed Apr 3, 2021
1 parent 5a1b02c commit c801d80
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
24 changes: 23 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"webpack-cli": "^4.6.0"
},
"dependencies": {
"joplin-turndown-plugin-gfm": "^1.0.12",
"turndown": "^7.0.0"
}
}
21 changes: 11 additions & 10 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TurndownService from 'turndown'
import { gfm } from 'joplin-turndown-plugin-gfm'

// Uncomment to bust any cached settings while debugging
// localStorage.clear();
Expand All @@ -24,7 +25,7 @@ import TurndownService from 'turndown'
*/
const settings = new Store('settings', {
// Render these elements into markdown output as HTML
keep_elements: 'table, small',
keep_elements: '',
// Do not consider these elements when rendering markdown output
delete_elements:
'script, style, title, noscript, canvas, embed, object, param, svg, source, iframe',
Expand All @@ -42,19 +43,19 @@ import TurndownService from 'turndown'
}
let turndownService = new TurndownService(turndownOptions)

// Use GitHub Flavored Markdown Turndown plugin
// Fop better table and strikethrough support

// Use the gfm plugin
turndownService.use(gfm)

// Use the table and strikethrough plugins only
// turndownService.use([tables, strikethrough])

// Apply settings for elements to keep and delete
turndownService.remove(deleteElements)
turndownService.keep(keepElements)

// Suport ~strikethrough~
// Taken from example at https://github.com/domchristie/turndown#methods
turndownService.addRule('strikethrough', {
filter: ['del', 's', 'strike'],
replacement: function (content) {
return '~' + content + '~'
},
})

// Fence all <pre> elements
// GitHub, for example, does not use <code> elements in their code blocks.
// See https://github.com/domchristie/turndown/issues/192
Expand Down
2 changes: 1 addition & 1 deletion src/options_custom/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ this.manifest = {
"name": "keep_elements",
"type": "textarea",
"text": "div, span, table, del, etc",
"default": "table, small"
"default": ""
},
{
"tab": "Options",
Expand Down

0 comments on commit c801d80

Please sign in to comment.