-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix incorrect tag completion in code block #341
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
Merged
sota1235
merged 15 commits into
BoostIO:master
from
asmsuechan:fix-incorrect-tag-completion
Apr 29, 2017
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
04097ec
Fix incorrect tag completion in code block
asmsuechan f7e0cb6
Add question mark
asmsuechan e60a543
Fix to replace only CodeBlock
asmsuechan 10043cc
Fix to handle when codeBlocks is null
asmsuechan 6229ca7
Refactor to ES6
asmsuechan cd2dc47
Fix to string literal
asmsuechan 1daf07e
Refactor to more readable
asmsuechan 39274ce
Fix to handle with multiple entities in one line
asmsuechan adf8117
Reduce the code
asmsuechan 003d8a1
Fix a bug on regexp of a question mark
asmsuechan 7146411
Remove a disused condition
asmsuechan 1722e10
Change methods to helper methods
asmsuechan 8e2fd30
Delete an encode table
asmsuechan b695d27
Add test for htmlTextHelper
asmsuechan 2df295d
Fix styles by lint
asmsuechan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @fileoverview Text trimmer for html. | ||
*/ | ||
|
||
/** | ||
* @param {string} text | ||
* @return {string} | ||
*/ | ||
|
||
export function decodeEntities (text) { | ||
var entities = [ | ||
['apos', '\''], | ||
['amp', '&'], | ||
['lt', '<'], | ||
['gt', '>'], | ||
['#63', '\\?'] | ||
] | ||
|
||
for (var i = 0, max = entities.length; i < max; ++i) { | ||
text = text.replace(new RegExp(`&${entities[i][0]};`, 'g'), entities[i][1]) | ||
} | ||
|
||
return text | ||
} | ||
|
||
export function encodeEntities (text) { | ||
const entities = [ | ||
['\'', 'apos'], | ||
['<', 'lt'], | ||
['>', 'gt'], | ||
['\\?', '#63'] | ||
] | ||
|
||
entities.forEach((entity) => { | ||
text = text.replace(new RegExp(entity[0], 'g'), `&${entity[1]};`) | ||
}) | ||
return text | ||
} | ||
|
||
export default { | ||
decodeEntities, | ||
encodeEntities | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @fileoverview Unit test for browser/lib/htmlTextHelper | ||
*/ | ||
const test = require('ava') | ||
const htmlTextHelper = require('browser/lib/htmlTextHelper') | ||
|
||
// Unit test | ||
test('htmlTextHelper#decodeEntities should return encoded text (string)', t => { | ||
// [input, expected] | ||
const testCases = [ | ||
['<a href=', '<a href='], | ||
['var test = 'test'', 'var test = \'test\''], | ||
['<a href='https://boostnote.io'>Boostnote', '<a href=\'https://boostnote.io\'>Boostnote'], | ||
['<\\\\?php\n var = 'hoge';', '<\\\\?php\n var = \'hoge\';'], | ||
['&', '&'] | ||
] | ||
|
||
testCases.forEach(testCase => { | ||
const [input, expected] = testCase | ||
t.is(htmlTextHelper.decodeEntities(input), expected, `Test for decodeEntities() input: ${input} expected: ${expected}`) | ||
}) | ||
}) | ||
|
||
test('htmlTextHelper#decodeEntities() should return decoded text (string)', t => { | ||
// [input, expected] | ||
const testCases = [ | ||
['<a href=', '<a href='], | ||
['var test = \'test\'', 'var test = 'test''], | ||
['<a href=\'https://boostnote.io\'>Boostnote', '<a href='https://boostnote.io'>Boostnote'], | ||
['<?php\n var = \'hoge\';', '<?php\n var = 'hoge';'] | ||
] | ||
|
||
testCases.forEach(testCase => { | ||
const [input, expected] = testCase | ||
t.is(htmlTextHelper.encodeEntities(input), expected, `Test for encodeEntities() input: ${input} expected: ${expected}`) | ||
}) | ||
}) | ||
|
||
// Integration test | ||
test(t => { | ||
const testCases = [ | ||
'var test = \'test\'', | ||
'<a href=\'https://boostnote.io\'>Boostnote', | ||
'<Component styleName=\'test\' />' | ||
] | ||
|
||
testCases.forEach(testCase => { | ||
const encodedText = htmlTextHelper.encodeEntities(testCase) | ||
const decodedText = htmlTextHelper.decodeEntities(encodedText) | ||
t.is(decodedText, testCase, 'Integration test through encodedText() and decodedText()') | ||
}) | ||
}) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are good JavaScript Engineer 👍