Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add replacements for Polar Bear markup language
- Loading branch information
Showing
14 changed files
with
155 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export default function bearStyleCodeBlock (turndownService) { | ||
turndownService.addRule('bearStyleCodeBlock', { | ||
filter: function (node) { | ||
let child = node.firstChild | ||
return ( | ||
node.nodeName === 'PRE' && | ||
child && | ||
child.nodeName === 'CODE' && | ||
child.classList.contains('code-multiline') | ||
) | ||
}, | ||
replacement: function (content, node, options) { | ||
let child = node.firstChild | ||
return ( | ||
'\n```' + child.lang + '\n' + | ||
child.textContent + | ||
'\n' + '```\n' | ||
) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function selectTodoCheckbox (node) { | ||
return node.firstElementChild | ||
} | ||
|
||
function selectTodoText (node) { | ||
return node.firstElementChild && node.firstElementChild.nextElementSibling | ||
} | ||
|
||
export default function todo (turndownService) { | ||
turndownService.addRule('todo', { | ||
filter: function (node) { | ||
var todoCheckboxElement = selectTodoCheckbox(node) | ||
var todoTextElement = selectTodoText(node) | ||
|
||
return node.nodeName === 'LI' && | ||
todoCheckboxElement && | ||
todoTextElement && | ||
todoCheckboxElement.classList.contains('todo-checkbox') && | ||
todoTextElement.classList.contains('todo-text') | ||
}, | ||
replacement: function (content, node) { | ||
var checked = selectTodoCheckbox(node) | ||
.classList | ||
.contains('todo-checked') | ||
|
||
return ( | ||
checked | ||
? '+ ' | ||
: '- ' | ||
) + content | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function bold (turndownService) { | ||
turndownService.addRule('bold', { | ||
filter: ['b', 'strong'], | ||
replacement: function (content) { | ||
return '*' + content + '*' | ||
} | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export default function todo (turndownService) { | ||
turndownService.addRule('todo', { | ||
filter: function (node) { | ||
return node.nodeName === 'LI' && | ||
node.firstChild && | ||
node.firstChild.type === 'checkbox' | ||
}, | ||
replacement: function (content, node) { | ||
return ( | ||
node.firstChild.checked | ||
? '+ ' | ||
: '- ' | ||
) + content | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function italic (turndownService) { | ||
turndownService.addRule('italic', { | ||
filter: ['i', 'em'], | ||
replacement: function (content) { | ||
return '/' + content + '/' | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function lineSeparator (turndownService) { | ||
turndownService.addRule('lineSeparator', { | ||
filter: ['hr'], | ||
replacement: function () { | ||
return '---' | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function mark (turndownService) { | ||
turndownService.addRule('mark', { | ||
filter: ['mark'], | ||
replacement: function (content) { | ||
return '::' + content + '::' | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import bearStyleCodeBlock from './bear-style-code-block' | ||
import bearStyleTodo from './bear-style-todo' | ||
import bold from './bold' | ||
import githubStyleCodeBlock from './github-style-code-block' | ||
import githubStyleTodo from './github-style-todo' | ||
import lineSeparator from './line-separator' | ||
import italic from './italic' | ||
import mark from './mark' | ||
import strikethrough from './strikethrough' | ||
import underline from './underline' | ||
|
||
function bear (turndownService) { | ||
turndownService.use([ | ||
bearStyleCodeBlock, | ||
bearStyleTodo, | ||
bold, | ||
githubStyleCodeBlock, | ||
githubStyleTodo, | ||
italic, | ||
lineSeparator, | ||
mark, | ||
strikethrough, | ||
underline | ||
]) | ||
} | ||
|
||
export { | ||
bear, | ||
bearStyleCodeBlock, | ||
bearStyleTodo, | ||
bold, | ||
githubStyleCodeBlock, | ||
githubStyleTodo, | ||
italic, | ||
lineSeparator, | ||
mark, | ||
strikethrough, | ||
underline | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function underline (turndownService) { | ||
turndownService.addRule('underline', { | ||
filter: ['u'], | ||
replacement: function (content) { | ||
return '_' + content + '_' | ||
} | ||
}) | ||
} |