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

Update Tokenizer to treat Markdown code as text instead of HTML #1

Merged
merged 2 commits into from
Feb 3, 2018
Merged
Changes from 1 commit
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: 7 additions & 1 deletion lib/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ function Tokenizer(options, cbs){
this._ended = false;
this._xmlMode = !!(options && options.xmlMode);
this._decodeEntities = !!(options && options.decodeEntities);
this._isMarkdownCode = false;
}

Tokenizer.prototype._stateText = function(c){
if(c === "<"){
// Parse open tag if it is not Markdown
if(c === "<" && !this._isMarkdownCode){
if(this._index > this._sectionStart){
this._cbs.ontext(this._getSection());
}
Expand Down Expand Up @@ -635,6 +637,10 @@ Tokenizer.prototype.write = function(chunk){
Tokenizer.prototype._parse = function(){
while(this._index < this._buffer.length && this._running){
var c = this._buffer.charAt(this._index);
// Detect Markdown code so that it is parsed as text instead of HTML
if(c === '`'){
this._isMarkdownCode = !this._isMarkdownCode;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Add a newline before and after this entire block.
  • Maybe add a section name like the ones below.

Copy link
Author

Choose a reason for hiding this comment

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

By section name, do you mean changing '=' into something like EQUALS?

if(nextChar === EQUALS){
    this._isInequality = true;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Would special conditions be an appropriate section name?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fine for now.

if(this._state === TEXT) {
this._stateText(c);
} else if(this._state === BEFORE_TAG_NAME){
Expand Down