npm install turndown
npm install @nhannht/turndown-plugin-gfm
All the examples below was output directly from /Org babel/. So at least you can ensure simple case like these examples will work
This pack is built from multi smaller parts, but you can quick import them all by call turndownService.use(turndownPluginGfm.org)
as below:
Suppose we want to turn a code block from vietnam-war-britannica
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.org
turndownService.use(org)
var complex1 = '<p class="topic-paragraph"><strong><span id="ref227172"></span>Vietnam War</strong>, (1954–75), a protracted conflict that pitted the <span id="ref227179"></span><a href="https://www.britannica.com/topic/communist-party-politics" class="md-crosslink">communist</a> government of North Vietnam and its allies in South Vietnam, known as the <span id="ref291137"></span><a href="https://www.britannica.com/topic/Viet-Cong" class="md-crosslink">Viet Cong</a>, against the government of South Vietnam and its principal ally, the <span id="ref227181"></span><a href="https://www.britannica.com/place/United-States" class="md-crosslink">United States</a>. Called the “American War” in Vietnam (or, in full, the “War Against the Americans to Save the Nation”), the war was also part of a larger regional conflict (<em>see</em> <a href="https://www.britannica.com/event/Indochina-wars" class="md-crosslink">Indochina wars</a>) and a <a href="https://www.merriam-webster.com/dictionary/manifestation" class="md-dictionary-link md-dictionary-tt-off" data-term="manifestation">manifestation</a> of the <a href="https://www.britannica.com/event/Cold-War" class="md-crosslink">Cold War</a> between the United States and the <a href="https://www.britannica.com/place/Soviet-Union" class="md-crosslink">Soviet Union</a> and their respective allies.</p>'
console.log(turndownService.turndown(complex1))
=Vietnam War=, (1954–75), a protracted conflict that pitted the [[https://www.britannica.com/topic/communist-party-politics][communist]] government of North Vietnam and its allies in South Vietnam, known as the [[https://www.britannica.com/topic/Viet-Cong][Viet Cong]], against the government of South Vietnam and its principal ally, the [[https://www.britannica.com/place/United-States][United States]]. Called the “American War” in Vietnam (or, in full, the “War Against the Americans to Save the Nation”), the war was also part of a larger regional conflict (/see/ [[https://www.britannica.com/event/Indochina-wars][Indochina wars]]) and a [[https://www.merriam-webster.com/dictionary/manifestation][manifestation]] of the [[https://www.britannica.com/event/Cold-War][Cold War]] between the United States and the [[https://www.britannica.com/place/Soviet-Union][Soviet Union]] and their respective allies.
undefined
Vietnam War
, (1954–75), a protracted conflict that pitted the communist government of North Vietnam and its allies in South Vietnam, known as the Viet Cong, against the government of South Vietnam and its principal ally, the United States. Called the “American War” in Vietnam (or, in full, the “War Against the Americans to Save the Nation”), the war was also part of a larger regional conflict (see Indochina wars) and a manifestation of the Cold War between the United States and the Soviet Union and their respective allies.
undefined
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgTables
turndownService.use(org)
const tableHTML = '<table> <thead> <tr> <th>header1</th> <th>header2</th> <th>header3</th> </tr> </thead> <tbody> <tr> <td>text1.1</td> <td>text1.2</td> <td>text1.3</td> </tr> <tr> <td>text2.1</td> <td>text2.2</td> <td>text2.3</td> </tr> <tr> <td>text3.1</td> <td>text3.2</td> <td>text3.3</td> </tr> <tr> </tr> </tbody> </table>'
console.log(turndownService.turndown(tableHTML))
| header1 | header2 | header3 |
|---------+---------+---------|
| text1.1 | text1.2 | text1.3 |
| text2.1 | text2.2 | text2.3 |
| text3.1 | text3.2 | text3.3 |
undefined
header1 | header2 | header3 |
---|---|---|
text1.1 | text1.2 | text1.3 |
text2.1 | text2.2 | text2.3 |
text3.1 | text3.2 | text3.3 |
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgBold
turndownService.use(org)
var boldHtml = '<html> <head> <title>Bold text</title> </head> <body> <p>Use the strong element to <strong>indicate strongly emphasized</strong> content.</p> </body> </html>'
console.log(turndownService.turndown(boldHtml))
Bold text
Use the strong element to =indicate strongly emphasized= content.
undefined
Bold text
Use the strong element to indicate strongly emphasized
content.
undefined
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgItalic
turndownService.use(org)
var italicHTML = '<i>This text will be in italics</i>'
console.log(turndownService.turndown(italicHTML))
/This text will be in italics/
undefined
This text will be in italics
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgStrikeThrough
turndownService.use(org)
var strikethroughHTML = '<p><strike>Hello WWorld</strike></p>'
var strikethroughHTML2 = '<p><del>Hello WWorld</del></p>'
console.log(turndownService.turndown(strikethroughHTML))
console.log(turndownService.turndown(strikethroughHTML2))
+Hello WWorld+
+Hello WWorld+
undefined
Hello WWorld
Hello WWorld
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgInlineCode
turndownService.use(org)
var inlineCodeHTML = '<p>The function <code>selectAll()</code> highlights all the text in the input field so the user can, for example, copy or delete the text.</p>'
console.log(turndownService.turndown(inlineCodeHTML))
The function =selectAll()= highlights all the text in the input field so the user can, for example, copy or delete the text.
undefined
The function selectAll()
highlights all the text in the input field so the user can, for example, copy or delete the text.
undefined
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgHeading
turndownService.use(org)
var headingHTML = "<h1>I'm the biggest heading</h1> <h2>I'm smaller than h1</h2> <h3>I'm smaller than h2</h3> <h4>I'm smaller than h3</h4> <h5>I'm smaller than h4</h5> <h6>I'm the smallest heading</h6>"
console.log(turndownService.turndown(headingHTML))
* I'm the biggest heading
** I'm smaller than h1
*** I'm smaller than h2
**** I'm smaller than h3
***** I'm smaller than h4
****** I'm the smallest heading
undefined
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgHighlight
turndownService.use(org)
var highlightHTML = "<p>Do not forget to buy <mark>milk</mark> today.</p>"
console.log(turndownService.turndown(highlightHTML))
Do not forget to buy *milk* today.
undefined
Do not forget to buy milk today.
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgHorizoneRule
turndownService.use(org)
var hrHTML = "The <hr> tag in HTML stands for horizontal rule and is used to insert a horizontal rule or a thematic break in an HTML page to divide or separate document sections. The <hr> tag is an empty tag and it does not require an end tag."
console.log(turndownService.turndown(hrHTML))
The
-----
tag in HTML stands for horizontal rule and is used to insert a horizontal rule or a thematic break in an HTML page to divide or separate document sections. The
-----
tag is an empty tag and it does not require an end tag.
undefined
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgImage
turndownService.use(org)
const imageHTML = '<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="600">'
console.log(turndownService.turndown(imageHTML))
[[img_girl.jpg][Girl in a jacket]]
undefined
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgSubscript
turndownService.use(org)
var subScriptHTML = "<p>This text contains Hello<sub>subscript</sub> text.</p>"
console.log(turndownService.turndown(subScriptHTML))
This text contains Hello_{subscript} text.
undefined
This text contains Hellosubscript text.
var TurndownService = require('turndown')
var turndownPluginGfm = require('@nhannht/turndown-plugin-gfm')
var turndownService = new TurndownService()
var org = turndownPluginGfm.orgSuperscript
turndownService.use(org)
var superScripttHTML = "Hello<sup>This is a superscript</sup>"
console.log(turndownService.turndown(superScripttHTML))
Hello^{This is a superscript}
undefined
# turndown-plugin-gfm
A [Turndown](https://github.com/domchristie/turndown) plugin which adds GitHub Flavored Markdown extensions.
## Installation
npm:
```
npm install turndown-plugin-gfm
```
Browser:
```html
<script src="https://unpkg.com/turndown/dist/turndown.js"></script>
<script src="https://unpkg.com/turndown-plugin-gfm/dist/turndown-plugin-gfm.js"></script>
```
## Usage
```js
// For Node.js
var TurndownService = require('turndown')
var turndownPluginGfm = require('turndown-plugin-gfm')
var gfm = turndownPluginGfm.gfm
var turndownService = new TurndownService()
turndownService.use(gfm)
var markdown = turndownService.turndown('<strike>Hello world!</strike>')
```
turndown-plugin-gfm is a suite of plugins which can be applied individually. The available plugins are as follows:
- `strikethrough` (for converting `<strike>`, `<s>`, and `<del>` elements)
- `tables`
- `taskListItems`
- `gfm` (which applies all of the above)
So for example, if you only wish to convert tables:
```js
var tables = require('turndown-plugin-gfm').tables
var turndownService = new TurndownService()
turndownService.use(tables)
```
## License
turndown-plugin-gfm is copyright © 2017+ Dom Christie and released under the MIT license.