Socket
Socket
Sign inDemoInstall

micromark-extension-gfm-autolink-literal

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micromark-extension-gfm-autolink-literal - npm Package Compare versions

Comparing version 0.5.5 to 0.5.6

5

html.js

@@ -23,6 +23,7 @@ var normalizeUri = require('micromark/dist/util/normalize-uri')

var url = this.sliceSerialize(token)
var href = this.encode(normalizeUri(url))
this.tag('<a href="' + (protocol || '') + href + '">')
this.tag(
'<a href="' + this.encode(normalizeUri((protocol || '') + url)) + '">'
)
this.raw(this.encode(url))
this.tag('</a>')
}

4

package.json
{
"name": "micromark-extension-gfm-autolink-literal",
"version": "0.5.5",
"version": "0.5.6",
"description": "micromark extension to support GFM autolink literals",

@@ -34,3 +34,3 @@ "license": "MIT",

"dependencies": {
"micromark": "~2.11.0"
"micromark": "~2.11.3"
},

@@ -37,0 +37,0 @@ "devDependencies": {

@@ -13,10 +13,22 @@ # micromark-extension-gfm-autolink-literal

autolinks][].
This syntax extension matches the GFM spec and github.com.
This syntax extension matches the GFM spec and how literal autolinks work
in several places on github.com.
Do note that GH employs two algorithms to autolink: one at parse time,
one at compile time (similar to how @mentions are done at compile time).
This difference can be observed because character references and escapes
are handled differently.
But also because issues/PRs/comments omit (perhaps by accident?) the second
algorithm for `www.`, `http://`, and `https://` links (but not for email links).
As this is a syntax extension, it focuses on the first algorithm.
The `html` part of this extension does not operate on an AST and hence can’t
perform the second algorithm.
`mdast-util-gfm-autolink-literal` adds support for the second.
This package provides the low-level modules for integrating with the micromark
tokenizer and the micromark HTML compiler.
You probably shouldn’t use this package directly, but instead use
[`mdast-util-gfm-autolink-literal`][mdast-util-gfm-autolink-literal] with
**[mdast][]**.
You probably should use this package with
[`mdast-util-gfm-autolink-literal`][mdast-util-gfm-autolink-literal].

@@ -120,6 +132,4 @@ ## Install

[mdast]: https://github.com/syntax-tree/mdast
[mdast-util-gfm-autolink-literal]: https://github.com/syntax-tree/mdast-util-gfm-autolink-literal
[literal autolinks]: https://github.github.com/gfm/#autolinks-extension-

@@ -8,10 +8,11 @@ var asciiAlpha = require('micromark/dist/character/ascii-alpha')

var www = {tokenize: tokenizeWww}
var http = {tokenize: tokenizeHttp}
var domain = {tokenize: tokenizeDomain}
var path = {tokenize: tokenizePath}
var punctuation = {tokenize: tokenizePunctuation}
var domainPunctuation = {tokenize: tokenizeDomainPunctuation}
var paren = {tokenize: tokenizeParen}
var namedCharacterReference = {tokenize: tokenizeNamedCharacterReference}
var www = {tokenize: tokenizeWww, partial: true}
var domain = {tokenize: tokenizeDomain, partial: true}
var path = {tokenize: tokenizePath, partial: true}
var punctuation = {tokenize: tokenizePunctuation, partial: true}
var paren = {tokenize: tokenizeParen, partial: true}
var namedCharacterReference = {
tokenize: tokenizeNamedCharacterReference,
partial: true
}

@@ -63,3 +64,7 @@ var wwwAutolink = {tokenize: tokenizeWwwAutolink, previous: previousWww}

/* istanbul ignore next - hooks. */
if (!gfmAtext(code) || !previousEmail(self.previous)) {
if (
!gfmAtext(code) ||
!previousEmail(self.previous) ||
previous(self.events)
) {
return nok(code)

@@ -149,3 +154,7 @@ }

/* istanbul ignore next - hooks. */
if ((code !== 87 && code - 32 !== 87) || !previousWww(self.previous)) {
if (
(code !== 87 && code - 32 !== 87) ||
!previousWww(self.previous) ||
previous(self.events)
) {
return nok(code)

@@ -156,2 +165,5 @@ }

effects.enter('literalAutolinkWww')
// For `www.` we check instead of attempt, because when it matches, GH
// treats it as part of a domain (yes, it says a valid domain must come
// after `www.`, but that’s not how it’s implemented by them).
return effects.check(

@@ -178,3 +190,7 @@ www,

/* istanbul ignore next - hooks. */
if ((code !== 72 && code - 32 !== 72) || !previousHttp(self.previous)) {
if (
(code !== 72 && code - 32 !== 72) ||
!previousHttp(self.previous) ||
previous(self.events)
) {
return nok(code)

@@ -185,21 +201,2 @@ }

effects.enter('literalAutolinkHttp')
return effects.check(
http,
effects.attempt(domain, effects.attempt(path, done), nok),
nok
)(code)
}
function done(code) {
effects.exit('literalAutolinkHttp')
effects.exit('literalAutolink')
return ok(code)
}
}
function tokenizeHttp(effects, ok, nok) {
return start
function start(code) {
// Assume a `h`.
effects.consume(code)

@@ -284,4 +281,10 @@ return t1

? nok(code)
: ok(code)
: effects.attempt(domain, effects.attempt(path, done), nok)(code)
}
function done(code) {
effects.exit('literalAutolinkHttp')
effects.exit('literalAutolink')
return ok(code)
}
}

@@ -334,3 +337,2 @@

function tokenizeDomain(effects, ok, nok) {
var opened
var hasUnderscoreInLastSegment

@@ -342,11 +344,2 @@ var hasUnderscoreInLastLastSegment

function domain(code) {
if (
// `/`
code === 47 ||
asciiControl(code) ||
unicodeWhitespace(code)
) {
return done(code)
}
// `&`

@@ -361,15 +354,19 @@ if (code === 38) {

if (code === 46 /* `.` */ || code === 95 /* `_` */) {
return effects.check(punctuation, done, punctuationContinuation)(code)
}
// GH documents that only alphanumerics (other than `-`, `.`, and `_`) can
// occur, which sounds like ASCII only, but they also support `www.點看.com`,
// so that’s Unicode.
// Instead of some new production for Unicode alphanumerics, markdown
// already has that for Unicode punctuation and whitespace, so use those.
if (
// `.`
code === 46 ||
trailingPunctuation(code)
asciiControl(code) ||
unicodeWhitespace(code) ||
(code !== 45 /* `-` */ && unicodePunctuation(code))
) {
return effects.check(
domainPunctuation,
done,
punctuationContinuation
)(code)
return done(code)
}
open()
effects.consume(code)

@@ -384,3 +381,2 @@ return domain

hasUnderscoreInLastSegment = undefined
open()
effects.consume(code)

@@ -393,3 +389,2 @@ return domain

open()
effects.consume(code)

@@ -399,16 +394,4 @@ return domain

function open() {
if (!opened) {
effects.enter('literalAutolinkDomain')
opened = true
}
}
function done(code) {
if (
opened &&
!hasUnderscoreInLastLastSegment &&
!hasUnderscoreInLastSegment
) {
effects.exit('literalAutolinkDomain')
if (!hasUnderscoreInLastLastSegment && !hasUnderscoreInLastSegment) {
return ok(code)

@@ -424,14 +407,4 @@ }

return start
return inPath
function start(code) {
// `/`
return code === 47 ? atPathStart(code) : ok(code)
}
function atPathStart(code) {
effects.enter('literalAutolinkPath')
return inPath(code)
}
function inPath(code) {

@@ -442,3 +415,3 @@ // `&`

namedCharacterReference,
atPathEnd,
ok,
continuedPunctuation

@@ -459,7 +432,7 @@ )(code)

if (pathEnd(code)) {
return atPathEnd(code)
return ok(code)
}
if (trailingPunctuation(code)) {
return effects.check(punctuation, atPathEnd, continuedPunctuation)(code)
return effects.check(punctuation, ok, continuedPunctuation)(code)
}

@@ -478,9 +451,4 @@

balance--
return balance < 0 ? atPathEnd(code) : continuedPunctuation(code)
return balance < 0 ? ok(code) : continuedPunctuation(code)
}
function atPathEnd(code) {
effects.exit('literalAutolinkPath')
return ok(code)
}
}

@@ -493,3 +461,2 @@

// Assume an ampersand.
effects.enter('literalAutolinkCharacterReferenceNamed')
effects.consume(code)

@@ -517,3 +484,2 @@ return inside

// not continued punctuation.
effects.exit('literalAutolinkCharacterReferenceNamed')
return pathEnd(code) ? ok(code) : nok(code)

@@ -528,3 +494,2 @@ }

// Assume a right paren.
effects.enter('literalAutolinkParen')
effects.consume(code)

@@ -537,3 +502,2 @@ return after

// continued punctuation.
effects.exit('literalAutolinkParen')
return pathEnd(code) ||

@@ -551,3 +515,2 @@ // `)`

function start(code) {
effects.enter('literalAutolinkPunctuation')
// Always a valid trailing punctuation marker.

@@ -559,20 +522,2 @@ effects.consume(code)

function after(code) {
// If the punctuation marker is followed by the end of the path, it’s not
// continued punctuation.
effects.exit('literalAutolinkPunctuation')
return pathEnd(code) ? ok(code) : nok(code)
}
}
function tokenizeDomainPunctuation(effects, ok, nok) {
return start
function start(code) {
effects.enter('literalAutolinkPunctuation')
// Always a valid trailing punctuation marker.
effects.consume(code)
return after
}
function after(code) {
// Check the next.

@@ -586,3 +531,2 @@ if (trailingPunctuation(code)) {

// continued punctuation.
effects.exit('literalAutolinkPunctuation')
return pathEnd(code) ? ok(code) : nok(code)

@@ -638,10 +582,6 @@ }

return (
// `+`
code === 43 ||
// `-`
code === 45 ||
// `.`
code === 46 ||
// `_`
code === 95 ||
code === 43 /* `+` */ ||
code === 45 /* `-` */ ||
code === 46 /* `.` */ ||
code === 95 /* `_` */ ||
asciiAlphanumeric(code)

@@ -655,4 +595,7 @@ )

code < 0 ||
unicodePunctuation(code) ||
unicodeWhitespace(code)
code === 32 /* ` ` */ ||
code === 40 /* `(` */ ||
code === 42 /* `*` */ ||
code === 95 /* `_` */ ||
code === 126 /* `~` */
)

@@ -668,1 +611,15 @@ }

}
function previous(events) {
var index = events.length
while (index--) {
if (
(events[index][1].type === 'labelLink' ||
events[index][1].type === 'labelImage') &&
!events[index][1]._balanced
) {
return true
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc