From b6e4e16e60cce1152d2060dce53cbf2899e0b2e9 Mon Sep 17 00:00:00 2001 From: almenon Date: Mon, 23 Dec 2019 22:26:04 -0800 Subject: [PATCH] add back converters from earlier --- exampleOutput.md | 8 +------- lib/convertFromUrl.js | 7 +++++++ lib/mdConverters.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 lib/mdConverters.js diff --git a/exampleOutput.md b/exampleOutput.md index a355ca0..031a9d0 100644 --- a/exampleOutput.md +++ b/exampleOutput.md @@ -5,13 +5,7 @@ Keeping yourself motivated as a coder ===================================== -[![Almenon](https://miro.medium.com/fit/c/96/96/1*4FAOBq9qVna6uHkxaolTtA.png)](https://medium.com/@almenon214?source=post_page-----a16a6fcf49c7----------------------) - -[Almenon](https://medium.com/@almenon214?source=post_page-----a16a6fcf49c7----------------------) - -Follow - -[Sep 23, 2018](https://medium.com/@almenon214/keeping-yourself-motivated-as-a-coder-a16a6fcf49c7?source=post_page-----a16a6fcf49c7----------------------) · 4 min read +[![Almenon](https://miro.medium.com/fit/c/96/96/1*4FAOBq9qVna6uHkxaolTtA.png)](https://medium.com/@almenon214?source=post_page-----a16a6fcf49c7----------------------)[Almenon](https://medium.com/@almenon214?source=post_page-----a16a6fcf49c7----------------------)Follow[Sep 23, 2018](https://medium.com/@almenon214/keeping-yourself-motivated-as-a-coder-a16a6fcf49c7?source=post_page-----a16a6fcf49c7----------------------) · 4 min read Programmers probably have one of the most distracting jobs in existence. Their entire workday is spent in front of a computer — a literally endless source of entertainment and pleasure, a limitless virtual heaven. With literally just a click of a button, you could be in another world. You could be slaying dragons. You could be learning about the [great molasses flood of 1919](https://www.damninteresting.com/the-great-molasses-flood-of-1919/). You could literally be doing _anything._ So why do programmers spend their time programming, a hobby that could only be described as exciting by masochistic workaholics? diff --git a/lib/convertFromUrl.js b/lib/convertFromUrl.js index d101f1d..3ef94e9 100644 --- a/lib/convertFromUrl.js +++ b/lib/convertFromUrl.js @@ -5,9 +5,16 @@ const cheerio = require('cheerio'); const TurndownService = require('turndown') const gfm = require('turndown-plugin-gfm').gfm +const converters = require('./mdConverters'); + + const turndownService = new TurndownService() turndownService.use(gfm) +converters.forEach((converter)=>{ + turndownService.addRule(converter.filter, converter) +}) + // following block adapted from https://github.com/domchristie/turndown/blob/61c2748c99fc53699896c1449f953ea492311c5b/src/commonmark-rules.js#L131 turndownService.addRule('mediumInlineLink', { filter: function (node, options) { diff --git a/lib/mdConverters.js b/lib/mdConverters.js new file mode 100644 index 0000000..2b5e646 --- /dev/null +++ b/lib/mdConverters.js @@ -0,0 +1,30 @@ +'use strict'; + +const converters = [ + { + filter: 'section', + replacement: function(content) { + return content; + } + }, + { + filter: 'div', + replacement: function(content) { + return content; + } + }, + { + filter: 'figure', + replacement: function(content) { + return content; + } + }, + { + filter: 'figcaption', + replacement: function(content) { + return content; + } + }, +] + +module.exports = converters \ No newline at end of file