Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades Remarkable and highlight.js #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

var fs = require('fs');
var path = require('path');
var Remarkable = require('remarkable');
var { Remarkable } = require('remarkable');
const { linkify } = require('remarkable/linkify');
var extend = require('extend-shallow');
var exists = require('fs-exists-sync');
var ent = require('ent');
Expand Down Expand Up @@ -106,12 +107,23 @@ helper.sync = function(name, options) {
*/

function markdown(options) {
return new Remarkable(extend({
breaks: false,
html: true,
langPrefix: 'lang-',
linkify: true,
typographer: false,
xhtmlOut: false
}, options));
const useLinkify = options.linkify === false ? false : true;
delete options.linkify;

let remarkable = new Remarkable(
extend(
{
breaks: false,
html: true,
langPrefix: 'lang-',
typographer: false,
xhtmlOut: false,
},
options
)
);
if (useLinkify) {
remarkable.use(linkify);
}
return remarkable;
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
"ent": "^2.2.0",
"extend-shallow": "^2.0.1",
"fs-exists-sync": "^0.1.0",
"remarkable": "^1.6.2"
"remarkable": "^2.0.1"
},
"devDependencies": {
"engine-base": "^0.1.2",
"gulp-format-md": "^0.1.9",
"handlebars": "^4.0.5",
"highlight.js": "^9.3.0",
"highlight.js": "^11.9.0",
"lodash": "^4.12.0",
"mocha": "^2.4.5",
"templates": "^0.17.2"
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/e.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# EEE

```
```javascript
var message = 'This is an alert';
alert(message);
```
13 changes: 8 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ describe('lodash:', function() {

describe('highlight:', function(argument) {
it('should support syntax highlighting', function() {
var actual = md.sync('test/fixtures/e.md', {
highlight: function(code, lang) {
var actual = md.sync("test/fixtures/e.md", {
highlight: function (code, language) {
try {
try {
return hljs.highlight(lang, code).value;
return hljs.highlight(code, { language }).value;
} catch (err) {
if (!/Unknown language/i.test(err.message)) {
throw err;
Expand All @@ -140,8 +140,11 @@ describe('highlight:', function(argument) {
} catch (err) {
return code;
}
}
},
});
assert.equal(actual, '<h1>EEE</h1>\n<pre><code><span class="hljs-keyword">var</span> <span class="hljs-keyword">message</span> = <span class="hljs-string">\'This is an alert\'</span>;\nalert(<span class="hljs-keyword">message</span>);\n</code></pre>\n');
assert.equal(
actual,
'<h1>EEE</h1>\n<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> message = <span class="hljs-string">\'This is an alert\'</span>;\n<span class="hljs-title function_">alert</span>(message);\n</code></pre>\n'
);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper syntax for the code block is to specify a language after the triple back-ticks. If you remove javascript from test/fixtures/e.md this assert will pass without needing this modification, however you'll get a warning in your console notifying you that you forgot to pass in a language. Once I tested this and confirmed that it worked (without the javascript) I went ahead and added it and then updated the assertion.

});
});