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

Various bug fixs and enhancements on TeX math rendering #5

Open
wants to merge 3 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
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*jslint node: true */
'use strict';

const replaceNl = require('./md-html-util').replaceNl;

const escapeHtml = require('./md-html-util').escapeHtml

const unescapeMd = require('./md-html-util').unescapeMd;
Expand Down Expand Up @@ -153,11 +155,13 @@ module.exports = function math_plugin(md, options) {
options = options || {};

var inlineRenderer = function(tokens, idx){
return '<img eeimg="1" src="//www.zhihu.com/equation?tex=' + encodeURI(tokens[idx].content) + '" alt="' + escapeHtml(tokens[idx].content).trim() + '"/>'
return '<img eeimg="1" src="//www.zhihu.com/equation?tex=' + encodeURIComponent(tokens[idx].content)
+ '" alt="' + escapeHtml(replaceNl(tokens[idx].content)).trim() + '"/>'
};

var blockRenderer = function(tokens, idx){
return '<p><img eeimg="1" src="//www.zhihu.com/equation?tex=' + encodeURI(tokens[idx].content) + '" alt="' + escapeHtml(tokens[idx].content).trim() + '"/></p>'
return '<p><img eeimg="1" src="//www.zhihu.com/equation?tex=' + encodeURIComponent('\\displaystyle ' + tokens[idx].content)
+ '" alt="' + escapeHtml(replaceNl('\\displaystyle ' + tokens[idx].content)).trim() + '"/></p>'
}

var imageRenderer = function(tokens, idx) {
Expand Down
6 changes: 5 additions & 1 deletion md-html-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function replaceUnsafeChar(ch) {
return HTML_REPLACEMENTS[ch];
}

function replaceNl(str) {
return str.replace(/[\n]/g," ");
}

function escapeHtml(str) {
if (HTML_ESCAPE_TEST_RE.test(str)) {
return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar);
Expand Down Expand Up @@ -49,7 +53,7 @@ function beautifyDate(date) {
}



exports.replaceNl = replaceNl;
exports.escapeHtml = escapeHtml;
exports.unescapeMd = unescapeMd;
exports.removeHtmlTag = removeHtmlTag;
Expand Down