Skip to content

Commit b8fc0c7

Browse files
committed
Improve and simplify reference link normalization.
We now use the built in str.toLowerCase().toUpperCase(), which @rlidwka has shown does an accurate unicode case fold. This allows us to remove a huge lookup table and should both decrease the size of the library and speed things up. Closes #168.
1 parent 8072c6b commit b8fc0c7

File tree

4 files changed

+9
-70
lines changed

4 files changed

+9
-70
lines changed

LICENSE

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727

2828
---
2929

30-
lib/normalize-reference.js is a slightly modified version of
31-
https://github.com/dmoscrop/fold-case:
32-
33-
Copyright Mathias Bynens <https://mathiasbynens.be/>
34-
35-
Permission is hereby granted, free of charge, to any person obtaining
36-
a copy of this software and associated documentation files (the
37-
"Software"), to deal in the Software without restriction, including
38-
without limitation the rights to use, copy, modify, merge, publish,
39-
distribute, sublicense, and/or sell copies of the Software, and to
40-
permit persons to whom the Software is furnished to do so, subject to
41-
the following conditions:
42-
43-
The above copyright notice and this permission notice shall be
44-
included in all copies or substantial portions of the Software.
45-
46-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
47-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
49-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
50-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
51-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
52-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
53-
54-
---
55-
5630
lib/from-code-point.js is derived from a polyfill
5731
Copyright Mathias Bynens <http://mathiasbynens.be/>
5832

dingus/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ALL=commonmark.js
22
COMPONENTS=lodash.min.js jquery.min.js jquery.min.map bootstrap.min.js bootstrap.min.css
3-
LIBFILES=../lib/blocks.js ../lib/common.js ../lib/from-code-point.js ../lib/inlines.js ../lib/index.js ../lib/node.js ../lib/normalize-reference.js ../lib/render/xml.js ../lib/render/html.js ../lib/render/renderer.js
3+
LIBFILES=../lib/blocks.js ../lib/common.js ../lib/from-code-point.js ../lib/inlines.js ../lib/index.js ../lib/node.js ../lib/render/xml.js ../lib/render/html.js ../lib/render/renderer.js
44
BOWER=../node_modules/.bin/bower
55
BROWSERIFY=../node_modules/.bin/browserify
66
HTTPSERVER=../node_modules/.bin/http-server

lib/inlines.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
var Node = require('./node');
44
var common = require('./common');
5-
var normalizeReference = require('./normalize-reference');
65

76
var normalizeURI = common.normalizeURI;
87
var unescapeString = common.unescapeString;
@@ -86,6 +85,14 @@ var text = function(s) {
8685
return node;
8786
};
8887

88+
// normalize a reference in reference link (remove []s, trim,
89+
// collapse internal space, unicode case fold.
90+
// See commonmark/commonmark.js#168.
91+
var normalizeReference =
92+
function(string) {
93+
return string.slice(1, string.length - 1).trim().replace(/[ \t\r\n]+/,' ').toLowerCase().toUpperCase();
94+
}
95+
8996
// INLINE PARSER
9097

9198
// These are methods of an InlineParser object, defined below.

0 commit comments

Comments
 (0)