diff --git a/lexers/javascript.go b/lexers/javascript.go index 5a09ff0..e7a0500 100644 --- a/lexers/javascript.go +++ b/lexers/javascript.go @@ -65,6 +65,7 @@ var Javascript = Register(MustNewLexer( Filenames: []string{"*.js", "*.jsm"}, MimeTypes: []string{"application/javascript", "application/x-javascript", "text/x-javascript", "text/javascript"}, DotAll: true, + EnsureNL: true, }, JavascriptRules, )) diff --git a/lexers/testdata/javascript.actual b/lexers/testdata/javascript.actual new file mode 100644 index 0000000..d0eac9a --- /dev/null +++ b/lexers/testdata/javascript.actual @@ -0,0 +1,2 @@ +sum = parseInt(num1) + parseInt(num2) // "+" means "add" +alert("Sum = " + sum) // "+" means combine into a string \ No newline at end of file diff --git a/lexers/testdata/javascript.expected b/lexers/testdata/javascript.expected new file mode 100644 index 0000000..094b337 --- /dev/null +++ b/lexers/testdata/javascript.expected @@ -0,0 +1,29 @@ +[ + {"type":"NameOther","value":"sum"}, + {"type":"Text","value":" "}, + {"type":"Operator","value":"="}, + {"type":"Text","value":" "}, + {"type":"NameBuiltin","value":"parseInt"}, + {"type":"Punctuation","value":"("}, + {"type":"NameOther","value":"num1"}, + {"type":"Punctuation","value":")"}, + {"type":"Text","value":" "}, + {"type":"Operator","value":"+"}, + {"type":"Text","value":" "}, + {"type":"NameBuiltin","value":"parseInt"}, + {"type":"Punctuation","value":"("}, + {"type":"NameOther","value":"num2"}, + {"type":"Punctuation","value":")"}, + {"type":"Text","value":" "}, + {"type":"CommentSingle","value":"// \"+\" means \"add\"\n"}, + {"type":"NameOther","value":"alert"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralStringDouble","value":"\"Sum = \""}, + {"type":"Text","value":" "}, + {"type":"Operator","value":"+"}, + {"type":"Text","value":" "}, + {"type":"NameOther","value":"sum"}, + {"type":"Punctuation","value":")"}, + {"type":"Text","value":" "}, + {"type":"CommentSingle","value":"// \"+\" means combine into a string\n"} +]