micromark-extension-gfm-autolink-literal
Advanced tools
Comparing version 2.0.0 to 2.1.0
export {gfmAutolinkLiteral} from './lib/syntax.js' | ||
export {gfmAutolinkLiteralHtml} from './lib/html.js' | ||
/** | ||
* Augment types. | ||
*/ | ||
declare module 'micromark-util-types' { | ||
/** | ||
* Augment token with a field to improve performance. | ||
*/ | ||
interface Token { | ||
@@ -9,2 +15,5 @@ _gfmAutolinkLiteralWalkedInto?: boolean | ||
/** | ||
* Token types. | ||
*/ | ||
interface TokenTypeMap { | ||
@@ -11,0 +20,0 @@ literalAutolink: 'literalAutolink' |
@@ -9,6 +9,3 @@ /** | ||
*/ | ||
export function gfmAutolinkLiteralHtml(): HtmlExtension | ||
export type CompileContext = import('micromark-util-types').CompileContext | ||
export type Handle = import('micromark-util-types').Handle | ||
export type HtmlExtension = import('micromark-util-types').HtmlExtension | ||
export type Token = import('micromark-util-types').Token | ||
export function gfmAutolinkLiteralHtml(): HtmlExtension; | ||
import type { HtmlExtension } from 'micromark-util-types'; |
/** | ||
* @typedef {import('micromark-util-types').CompileContext} CompileContext | ||
* @typedef {import('micromark-util-types').Handle} Handle | ||
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension | ||
* @typedef {import('micromark-util-types').Token} Token | ||
* @import {CompileContext, Handle, HtmlExtension, Token} from 'micromark-util-types' | ||
*/ | ||
@@ -7,0 +4,0 @@ |
@@ -9,10 +9,3 @@ /** | ||
*/ | ||
export function gfmAutolinkLiteral(): Extension | ||
export type Code = import('micromark-util-types').Code | ||
export type ConstructRecord = import('micromark-util-types').ConstructRecord | ||
export type Event = import('micromark-util-types').Event | ||
export type Extension = import('micromark-util-types').Extension | ||
export type Previous = import('micromark-util-types').Previous | ||
export type State = import('micromark-util-types').State | ||
export type TokenizeContext = import('micromark-util-types').TokenizeContext | ||
export type Tokenizer = import('micromark-util-types').Tokenizer | ||
export function gfmAutolinkLiteral(): Extension; | ||
import type { Extension } from 'micromark-util-types'; |
/** | ||
* @typedef {import('micromark-util-types').Code} Code | ||
* @typedef {import('micromark-util-types').ConstructRecord} ConstructRecord | ||
* @typedef {import('micromark-util-types').Event} Event | ||
* @typedef {import('micromark-util-types').Extension} Extension | ||
* @typedef {import('micromark-util-types').Previous} Previous | ||
* @typedef {import('micromark-util-types').State} State | ||
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext | ||
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer | ||
* @import {Code, ConstructRecord, Event, Extension, Previous, State, TokenizeContext, Tokenizer} from 'micromark-util-types' | ||
*/ | ||
@@ -31,9 +24,20 @@ | ||
const wwwAutolink = {tokenize: tokenizeWwwAutolink, previous: previousWww} | ||
const wwwAutolink = { | ||
name: 'wwwAutolink', | ||
tokenize: tokenizeWwwAutolink, | ||
previous: previousWww | ||
} | ||
const protocolAutolink = { | ||
name: 'protocolAutolink', | ||
tokenize: tokenizeProtocolAutolink, | ||
previous: previousProtocol | ||
} | ||
const emailAutolink = {tokenize: tokenizeEmailAutolink, previous: previousEmail} | ||
const emailAutolink = { | ||
name: 'emailAutolink', | ||
tokenize: tokenizeEmailAutolink, | ||
previous: previousEmail | ||
} | ||
/** @type {ConstructRecord} */ | ||
@@ -745,3 +749,3 @@ const text = {} | ||
effects.consume(code) | ||
return trailCharRefStart | ||
return trailCharacterReferenceStart | ||
} | ||
@@ -810,5 +814,5 @@ | ||
*/ | ||
function trailCharRefStart(code) { | ||
function trailCharacterReferenceStart(code) { | ||
// When non-alpha, it’s not a trail. | ||
return asciiAlpha(code) ? trailCharRefInside(code) : nok(code) | ||
return asciiAlpha(code) ? trailCharacterReferenceInside(code) : nok(code) | ||
} | ||
@@ -826,3 +830,3 @@ | ||
*/ | ||
function trailCharRefInside(code) { | ||
function trailCharacterReferenceInside(code) { | ||
// Switch back to trail if this is well-formed. | ||
@@ -836,3 +840,3 @@ if (code === codes.semicolon) { | ||
effects.consume(code) | ||
return trailCharRefInside | ||
return trailCharacterReferenceInside | ||
} | ||
@@ -839,0 +843,0 @@ |
export {gfmAutolinkLiteral} from './lib/syntax.js' | ||
export {gfmAutolinkLiteralHtml} from './lib/html.js' | ||
/** | ||
* Augment types. | ||
*/ | ||
declare module 'micromark-util-types' { | ||
/** | ||
* Augment token with a field to improve performance. | ||
*/ | ||
interface Token { | ||
@@ -9,2 +15,5 @@ _gfmAutolinkLiteralWalkedInto?: boolean | ||
/** | ||
* Token types. | ||
*/ | ||
interface TokenTypeMap { | ||
@@ -11,0 +20,0 @@ literalAutolink: 'literalAutolink' |
@@ -1,2 +0,2 @@ | ||
export {gfmAutolinkLiteral} from './lib/syntax.js' | ||
export {gfmAutolinkLiteralHtml} from './lib/html.js' | ||
export { gfmAutolinkLiteral } from './lib/syntax.js'; | ||
export { gfmAutolinkLiteralHtml } from './lib/html.js'; |
@@ -9,6 +9,3 @@ /** | ||
*/ | ||
export function gfmAutolinkLiteralHtml(): HtmlExtension | ||
export type CompileContext = import('micromark-util-types').CompileContext | ||
export type Handle = import('micromark-util-types').Handle | ||
export type HtmlExtension = import('micromark-util-types').HtmlExtension | ||
export type Token = import('micromark-util-types').Token | ||
export function gfmAutolinkLiteralHtml(): HtmlExtension; | ||
import type { HtmlExtension } from 'micromark-util-types'; |
/** | ||
* @typedef {import('micromark-util-types').CompileContext} CompileContext | ||
* @typedef {import('micromark-util-types').Handle} Handle | ||
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension | ||
* @typedef {import('micromark-util-types').Token} Token | ||
* @import {CompileContext, Handle, HtmlExtension, Token} from 'micromark-util-types' | ||
*/ | ||
import {sanitizeUri} from 'micromark-util-sanitize-uri' | ||
import { sanitizeUri } from 'micromark-util-sanitize-uri'; | ||
@@ -25,3 +22,3 @@ /** | ||
} | ||
} | ||
}; | ||
} | ||
@@ -34,3 +31,3 @@ | ||
function literalAutolinkWww(token) { | ||
anchorFromToken.call(this, token, 'http://') | ||
anchorFromToken.call(this, token, 'http://'); | ||
} | ||
@@ -43,3 +40,3 @@ | ||
function literalAutolinkEmail(token) { | ||
anchorFromToken.call(this, token, 'mailto:') | ||
anchorFromToken.call(this, token, 'mailto:'); | ||
} | ||
@@ -52,3 +49,3 @@ | ||
function literalAutolinkHttp(token) { | ||
anchorFromToken.call(this, token) | ||
anchorFromToken.call(this, token); | ||
} | ||
@@ -63,6 +60,6 @@ | ||
function anchorFromToken(token, protocol) { | ||
const url = this.sliceSerialize(token) | ||
this.tag('<a href="' + sanitizeUri((protocol || '') + url) + '">') | ||
this.raw(this.encode(url)) | ||
this.tag('</a>') | ||
} | ||
const url = this.sliceSerialize(token); | ||
this.tag('<a href="' + sanitizeUri((protocol || '') + url) + '">'); | ||
this.raw(this.encode(url)); | ||
this.tag('</a>'); | ||
} |
@@ -9,10 +9,3 @@ /** | ||
*/ | ||
export function gfmAutolinkLiteral(): Extension | ||
export type Code = import('micromark-util-types').Code | ||
export type ConstructRecord = import('micromark-util-types').ConstructRecord | ||
export type Event = import('micromark-util-types').Event | ||
export type Extension = import('micromark-util-types').Extension | ||
export type Previous = import('micromark-util-types').Previous | ||
export type State = import('micromark-util-types').State | ||
export type TokenizeContext = import('micromark-util-types').TokenizeContext | ||
export type Tokenizer = import('micromark-util-types').Tokenizer | ||
export function gfmAutolinkLiteral(): Extension; | ||
import type { Extension } from 'micromark-util-types'; |
/** | ||
* @typedef {import('micromark-util-types').Code} Code | ||
* @typedef {import('micromark-util-types').ConstructRecord} ConstructRecord | ||
* @typedef {import('micromark-util-types').Event} Event | ||
* @typedef {import('micromark-util-types').Extension} Extension | ||
* @typedef {import('micromark-util-types').Previous} Previous | ||
* @typedef {import('micromark-util-types').State} State | ||
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext | ||
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer | ||
* @import {Code, ConstructRecord, Event, Extension, Previous, State, TokenizeContext, Tokenizer} from 'micromark-util-types' | ||
*/ | ||
import { | ||
asciiAlpha, | ||
asciiAlphanumeric, | ||
asciiControl, | ||
markdownLineEndingOrSpace, | ||
unicodePunctuation, | ||
unicodeWhitespace | ||
} from 'micromark-util-character' | ||
import { asciiAlpha, asciiAlphanumeric, asciiControl, markdownLineEndingOrSpace, unicodePunctuation, unicodeWhitespace } from 'micromark-util-character'; | ||
const wwwPrefix = { | ||
tokenize: tokenizeWwwPrefix, | ||
partial: true | ||
} | ||
}; | ||
const domain = { | ||
tokenize: tokenizeDomain, | ||
partial: true | ||
} | ||
}; | ||
const path = { | ||
tokenize: tokenizePath, | ||
partial: true | ||
} | ||
}; | ||
const trail = { | ||
tokenize: tokenizeTrail, | ||
partial: true | ||
} | ||
}; | ||
const emailDomainDotTrail = { | ||
tokenize: tokenizeEmailDomainDotTrail, | ||
partial: true | ||
} | ||
}; | ||
const wwwAutolink = { | ||
name: 'wwwAutolink', | ||
tokenize: tokenizeWwwAutolink, | ||
previous: previousWww | ||
} | ||
}; | ||
const protocolAutolink = { | ||
name: 'protocolAutolink', | ||
tokenize: tokenizeProtocolAutolink, | ||
previous: previousProtocol | ||
} | ||
}; | ||
const emailAutolink = { | ||
name: 'emailAutolink', | ||
tokenize: tokenizeEmailAutolink, | ||
previous: previousEmail | ||
} | ||
}; | ||
/** @type {ConstructRecord} */ | ||
const text = {} | ||
const text = {}; | ||
@@ -67,23 +56,22 @@ /** | ||
text | ||
} | ||
}; | ||
} | ||
/** @type {Code} */ | ||
let code = 48 | ||
let code = 48; | ||
// Add alphanumerics. | ||
while (code < 123) { | ||
text[code] = emailAutolink | ||
code++ | ||
if (code === 58) code = 65 | ||
else if (code === 91) code = 97 | ||
text[code] = emailAutolink; | ||
code++; | ||
if (code === 58) code = 65;else if (code === 91) code = 97; | ||
} | ||
text[43] = emailAutolink | ||
text[45] = emailAutolink | ||
text[46] = emailAutolink | ||
text[95] = emailAutolink | ||
text[72] = [emailAutolink, protocolAutolink] | ||
text[104] = [emailAutolink, protocolAutolink] | ||
text[87] = [emailAutolink, wwwAutolink] | ||
text[119] = [emailAutolink, wwwAutolink] | ||
text[43] = emailAutolink; | ||
text[45] = emailAutolink; | ||
text[46] = emailAutolink; | ||
text[95] = emailAutolink; | ||
text[72] = [emailAutolink, protocolAutolink]; | ||
text[104] = [emailAutolink, protocolAutolink]; | ||
text[87] = [emailAutolink, wwwAutolink]; | ||
text[119] = [emailAutolink, wwwAutolink]; | ||
@@ -108,8 +96,8 @@ // To do: perform email autolink literals on events, afterwards. | ||
function tokenizeEmailAutolink(effects, ok, nok) { | ||
const self = this | ||
const self = this; | ||
/** @type {boolean | undefined} */ | ||
let dot | ||
let dot; | ||
/** @type {boolean} */ | ||
let data | ||
return start | ||
let data; | ||
return start; | ||
@@ -127,12 +115,8 @@ /** | ||
function start(code) { | ||
if ( | ||
!gfmAtext(code) || | ||
!previousEmail.call(self, self.previous) || | ||
previousUnbalanced(self.events) | ||
) { | ||
return nok(code) | ||
if (!gfmAtext(code) || !previousEmail.call(self, self.previous) || previousUnbalanced(self.events)) { | ||
return nok(code); | ||
} | ||
effects.enter('literalAutolink') | ||
effects.enter('literalAutolinkEmail') | ||
return atext(code) | ||
effects.enter('literalAutolink'); | ||
effects.enter('literalAutolinkEmail'); | ||
return atext(code); | ||
} | ||
@@ -152,10 +136,10 @@ | ||
if (gfmAtext(code)) { | ||
effects.consume(code) | ||
return atext | ||
effects.consume(code); | ||
return atext; | ||
} | ||
if (code === 64) { | ||
effects.consume(code) | ||
return emailDomain | ||
effects.consume(code); | ||
return emailDomain; | ||
} | ||
return nok(code) | ||
return nok(code); | ||
} | ||
@@ -180,7 +164,3 @@ | ||
if (code === 46) { | ||
return effects.check( | ||
emailDomainDotTrail, | ||
emailDomainAfter, | ||
emailDomainDot | ||
)(code) | ||
return effects.check(emailDomainDotTrail, emailDomainAfter, emailDomainDot)(code); | ||
} | ||
@@ -190,5 +170,5 @@ | ||
if (code === 45 || code === 95 || asciiAlphanumeric(code)) { | ||
data = true | ||
effects.consume(code) | ||
return emailDomain | ||
data = true; | ||
effects.consume(code); | ||
return emailDomain; | ||
} | ||
@@ -202,3 +182,3 @@ | ||
// So we can ignore truncating! | ||
return emailDomainAfter(code) | ||
return emailDomainAfter(code); | ||
} | ||
@@ -217,5 +197,5 @@ | ||
function emailDomainDot(code) { | ||
effects.consume(code) | ||
dot = true | ||
return emailDomain | ||
effects.consume(code); | ||
dot = true; | ||
return emailDomain; | ||
} | ||
@@ -237,7 +217,7 @@ | ||
if (data && dot && asciiAlpha(self.previous)) { | ||
effects.exit('literalAutolinkEmail') | ||
effects.exit('literalAutolink') | ||
return ok(code) | ||
effects.exit('literalAutolinkEmail'); | ||
effects.exit('literalAutolink'); | ||
return ok(code); | ||
} | ||
return nok(code) | ||
return nok(code); | ||
} | ||
@@ -258,4 +238,4 @@ } | ||
function tokenizeWwwAutolink(effects, ok, nok) { | ||
const self = this | ||
return wwwStart | ||
const self = this; | ||
return wwwStart; | ||
@@ -273,18 +253,10 @@ /** | ||
function wwwStart(code) { | ||
if ( | ||
(code !== 87 && code !== 119) || | ||
!previousWww.call(self, self.previous) || | ||
previousUnbalanced(self.events) | ||
) { | ||
return nok(code) | ||
if (code !== 87 && code !== 119 || !previousWww.call(self, self.previous) || previousUnbalanced(self.events)) { | ||
return nok(code); | ||
} | ||
effects.enter('literalAutolink') | ||
effects.enter('literalAutolinkWww') | ||
effects.enter('literalAutolink'); | ||
effects.enter('literalAutolinkWww'); | ||
// Note: we *check*, so we can discard the `www.` we parsed. | ||
// If it worked, we consider it as a part of the domain. | ||
return effects.check( | ||
wwwPrefix, | ||
effects.attempt(domain, effects.attempt(path, wwwAfter), nok), | ||
nok | ||
)(code) | ||
return effects.check(wwwPrefix, effects.attempt(domain, effects.attempt(path, wwwAfter), nok), nok)(code); | ||
} | ||
@@ -303,5 +275,5 @@ | ||
function wwwAfter(code) { | ||
effects.exit('literalAutolinkWww') | ||
effects.exit('literalAutolink') | ||
return ok(code) | ||
effects.exit('literalAutolinkWww'); | ||
effects.exit('literalAutolink'); | ||
return ok(code); | ||
} | ||
@@ -322,6 +294,6 @@ } | ||
function tokenizeProtocolAutolink(effects, ok, nok) { | ||
const self = this | ||
let buffer = '' | ||
let seen = false | ||
return protocolStart | ||
const self = this; | ||
let buffer = ''; | ||
let seen = false; | ||
return protocolStart; | ||
@@ -339,14 +311,10 @@ /** | ||
function protocolStart(code) { | ||
if ( | ||
(code === 72 || code === 104) && | ||
previousProtocol.call(self, self.previous) && | ||
!previousUnbalanced(self.events) | ||
) { | ||
effects.enter('literalAutolink') | ||
effects.enter('literalAutolinkHttp') | ||
buffer += String.fromCodePoint(code) | ||
effects.consume(code) | ||
return protocolPrefixInside | ||
if ((code === 72 || code === 104) && previousProtocol.call(self, self.previous) && !previousUnbalanced(self.events)) { | ||
effects.enter('literalAutolink'); | ||
effects.enter('literalAutolinkHttp'); | ||
buffer += String.fromCodePoint(code); | ||
effects.consume(code); | ||
return protocolPrefixInside; | ||
} | ||
return nok(code) | ||
return nok(code); | ||
} | ||
@@ -368,14 +336,14 @@ | ||
// @ts-expect-error: definitely number. | ||
buffer += String.fromCodePoint(code) | ||
effects.consume(code) | ||
return protocolPrefixInside | ||
buffer += String.fromCodePoint(code); | ||
effects.consume(code); | ||
return protocolPrefixInside; | ||
} | ||
if (code === 58) { | ||
const protocol = buffer.toLowerCase() | ||
const protocol = buffer.toLowerCase(); | ||
if (protocol === 'http' || protocol === 'https') { | ||
effects.consume(code) | ||
return protocolSlashesInside | ||
effects.consume(code); | ||
return protocolSlashesInside; | ||
} | ||
} | ||
return nok(code) | ||
return nok(code); | ||
} | ||
@@ -395,10 +363,10 @@ | ||
if (code === 47) { | ||
effects.consume(code) | ||
effects.consume(code); | ||
if (seen) { | ||
return afterProtocol | ||
return afterProtocol; | ||
} | ||
seen = true | ||
return protocolSlashesInside | ||
seen = true; | ||
return protocolSlashesInside; | ||
} | ||
return nok(code) | ||
return nok(code); | ||
} | ||
@@ -419,9 +387,3 @@ | ||
// https://github.com/wooorm/markdown-rs/blob/b3a921c761309ae00a51fe348d8a43adbc54b518/src/construct/gfm_autolink_literal.rs#L172-L182 | ||
return code === null || | ||
asciiControl(code) || | ||
markdownLineEndingOrSpace(code) || | ||
unicodeWhitespace(code) || | ||
unicodePunctuation(code) | ||
? nok(code) | ||
: effects.attempt(domain, effects.attempt(path, protocolAfter), nok)(code) | ||
return code === null || asciiControl(code) || markdownLineEndingOrSpace(code) || unicodeWhitespace(code) || unicodePunctuation(code) ? nok(code) : effects.attempt(domain, effects.attempt(path, protocolAfter), nok)(code); | ||
} | ||
@@ -440,5 +402,5 @@ | ||
function protocolAfter(code) { | ||
effects.exit('literalAutolinkHttp') | ||
effects.exit('literalAutolink') | ||
return ok(code) | ||
effects.exit('literalAutolinkHttp'); | ||
effects.exit('literalAutolink'); | ||
return ok(code); | ||
} | ||
@@ -459,4 +421,4 @@ } | ||
function tokenizeWwwPrefix(effects, ok, nok) { | ||
let size = 0 | ||
return wwwPrefixInside | ||
let size = 0; | ||
return wwwPrefixInside; | ||
@@ -475,11 +437,11 @@ /** | ||
if ((code === 87 || code === 119) && size < 3) { | ||
size++ | ||
effects.consume(code) | ||
return wwwPrefixInside | ||
size++; | ||
effects.consume(code); | ||
return wwwPrefixInside; | ||
} | ||
if (code === 46 && size === 3) { | ||
effects.consume(code) | ||
return wwwPrefixAfter | ||
effects.consume(code); | ||
return wwwPrefixAfter; | ||
} | ||
return nok(code) | ||
return nok(code); | ||
} | ||
@@ -499,3 +461,3 @@ | ||
// If there is *anything*, we can link. | ||
return code === null ? nok(code) : ok(code) | ||
return code === null ? nok(code) : ok(code); | ||
} | ||
@@ -517,8 +479,8 @@ } | ||
/** @type {boolean | undefined} */ | ||
let underscoreInLastSegment | ||
let underscoreInLastSegment; | ||
/** @type {boolean | undefined} */ | ||
let underscoreInLastLastSegment | ||
let underscoreInLastLastSegment; | ||
/** @type {boolean | undefined} */ | ||
let seen | ||
return domainInside | ||
let seen; | ||
return domainInside; | ||
@@ -540,3 +502,3 @@ /** | ||
if (code === 46 || code === 95) { | ||
return effects.check(trail, domainAfter, domainAtPunctuation)(code) | ||
return effects.check(trail, domainAfter, domainAtPunctuation)(code); | ||
} | ||
@@ -550,13 +512,8 @@ | ||
// Source: <https://github.com/github/cmark-gfm/blob/ef1cfcb/extensions/autolink.c#L12>. | ||
if ( | ||
code === null || | ||
markdownLineEndingOrSpace(code) || | ||
unicodeWhitespace(code) || | ||
(code !== 45 && unicodePunctuation(code)) | ||
) { | ||
return domainAfter(code) | ||
if (code === null || markdownLineEndingOrSpace(code) || unicodeWhitespace(code) || code !== 45 && unicodePunctuation(code)) { | ||
return domainAfter(code); | ||
} | ||
seen = true | ||
effects.consume(code) | ||
return domainInside | ||
seen = true; | ||
effects.consume(code); | ||
return domainInside; | ||
} | ||
@@ -577,3 +534,3 @@ | ||
if (code === 95) { | ||
underscoreInLastSegment = true | ||
underscoreInLastSegment = true; | ||
} | ||
@@ -583,7 +540,7 @@ // Otherwise, it’s a `.`: save the last segment underscore in the | ||
else { | ||
underscoreInLastLastSegment = underscoreInLastSegment | ||
underscoreInLastSegment = undefined | ||
underscoreInLastLastSegment = underscoreInLastSegment; | ||
underscoreInLastSegment = undefined; | ||
} | ||
effects.consume(code) | ||
return domainInside | ||
effects.consume(code); | ||
return domainInside; | ||
} | ||
@@ -604,5 +561,5 @@ | ||
if (underscoreInLastLastSegment || underscoreInLastSegment || !seen) { | ||
return nok(code) | ||
return nok(code); | ||
} | ||
return ok(code) | ||
return ok(code); | ||
} | ||
@@ -623,5 +580,5 @@ } | ||
function tokenizePath(effects, ok) { | ||
let sizeOpen = 0 | ||
let sizeClose = 0 | ||
return pathInside | ||
let sizeOpen = 0; | ||
let sizeClose = 0; | ||
return pathInside; | ||
@@ -640,5 +597,5 @@ /** | ||
if (code === 40) { | ||
sizeOpen++ | ||
effects.consume(code) | ||
return pathInside | ||
sizeOpen++; | ||
effects.consume(code); | ||
return pathInside; | ||
} | ||
@@ -650,3 +607,3 @@ | ||
if (code === 41 && sizeClose < sizeOpen) { | ||
return pathAtPunctuation(code) | ||
return pathAtPunctuation(code); | ||
} | ||
@@ -657,30 +614,10 @@ | ||
// by an end. | ||
if ( | ||
code === 33 || | ||
code === 34 || | ||
code === 38 || | ||
code === 39 || | ||
code === 41 || | ||
code === 42 || | ||
code === 44 || | ||
code === 46 || | ||
code === 58 || | ||
code === 59 || | ||
code === 60 || | ||
code === 63 || | ||
code === 93 || | ||
code === 95 || | ||
code === 126 | ||
) { | ||
return effects.check(trail, ok, pathAtPunctuation)(code) | ||
if (code === 33 || code === 34 || code === 38 || code === 39 || code === 41 || code === 42 || code === 44 || code === 46 || code === 58 || code === 59 || code === 60 || code === 63 || code === 93 || code === 95 || code === 126) { | ||
return effects.check(trail, ok, pathAtPunctuation)(code); | ||
} | ||
if ( | ||
code === null || | ||
markdownLineEndingOrSpace(code) || | ||
unicodeWhitespace(code) | ||
) { | ||
return ok(code) | ||
if (code === null || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) { | ||
return ok(code); | ||
} | ||
effects.consume(code) | ||
return pathInside | ||
effects.consume(code); | ||
return pathInside; | ||
} | ||
@@ -701,6 +638,6 @@ | ||
if (code === 41) { | ||
sizeClose++ | ||
sizeClose++; | ||
} | ||
effects.consume(code) | ||
return pathInside | ||
effects.consume(code); | ||
return pathInside; | ||
} | ||
@@ -725,3 +662,3 @@ } | ||
function tokenizeTrail(effects, ok, nok) { | ||
return trail | ||
return trail; | ||
@@ -740,18 +677,5 @@ /** | ||
// Regular trailing punctuation. | ||
if ( | ||
code === 33 || | ||
code === 34 || | ||
code === 39 || | ||
code === 41 || | ||
code === 42 || | ||
code === 44 || | ||
code === 46 || | ||
code === 58 || | ||
code === 59 || | ||
code === 63 || | ||
code === 95 || | ||
code === 126 | ||
) { | ||
effects.consume(code) | ||
return trail | ||
if (code === 33 || code === 34 || code === 39 || code === 41 || code === 42 || code === 44 || code === 46 || code === 58 || code === 59 || code === 63 || code === 95 || code === 126) { | ||
effects.consume(code); | ||
return trail; | ||
} | ||
@@ -763,4 +687,4 @@ | ||
if (code === 38) { | ||
effects.consume(code) | ||
return trailCharRefStart | ||
effects.consume(code); | ||
return trailCharacterReferenceStart; | ||
} | ||
@@ -772,16 +696,13 @@ | ||
if (code === 93) { | ||
effects.consume(code) | ||
return trailBracketAfter | ||
effects.consume(code); | ||
return trailBracketAfter; | ||
} | ||
if ( | ||
// `<` is an end. | ||
code === 60 || | ||
// So is whitespace. | ||
code === null || | ||
markdownLineEndingOrSpace(code) || | ||
unicodeWhitespace(code) | ||
) { | ||
return ok(code) | ||
// `<` is an end. | ||
code === 60 || | ||
// So is whitespace. | ||
code === null || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) { | ||
return ok(code); | ||
} | ||
return nok(code) | ||
return nok(code); | ||
} | ||
@@ -805,12 +726,6 @@ | ||
// Switch back to trail otherwise. | ||
if ( | ||
code === null || | ||
code === 40 || | ||
code === 91 || | ||
markdownLineEndingOrSpace(code) || | ||
unicodeWhitespace(code) | ||
) { | ||
return ok(code) | ||
if (code === null || code === 40 || code === 91 || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) { | ||
return ok(code); | ||
} | ||
return trail(code) | ||
return trail(code); | ||
} | ||
@@ -828,5 +743,5 @@ | ||
*/ | ||
function trailCharRefStart(code) { | ||
function trailCharacterReferenceStart(code) { | ||
// When non-alpha, it’s not a trail. | ||
return asciiAlpha(code) ? trailCharRefInside(code) : nok(code) | ||
return asciiAlpha(code) ? trailCharacterReferenceInside(code) : nok(code); | ||
} | ||
@@ -844,15 +759,15 @@ | ||
*/ | ||
function trailCharRefInside(code) { | ||
function trailCharacterReferenceInside(code) { | ||
// Switch back to trail if this is well-formed. | ||
if (code === 59) { | ||
effects.consume(code) | ||
return trail | ||
effects.consume(code); | ||
return trail; | ||
} | ||
if (asciiAlpha(code)) { | ||
effects.consume(code) | ||
return trailCharRefInside | ||
effects.consume(code); | ||
return trailCharacterReferenceInside; | ||
} | ||
// It’s not a trail. | ||
return nok(code) | ||
return nok(code); | ||
} | ||
@@ -877,3 +792,3 @@ } | ||
function tokenizeEmailDomainDotTrail(effects, ok, nok) { | ||
return start | ||
return start; | ||
@@ -892,4 +807,4 @@ /** | ||
// Must be dot. | ||
effects.consume(code) | ||
return after | ||
effects.consume(code); | ||
return after; | ||
} | ||
@@ -909,3 +824,3 @@ | ||
// Not a trail if alphanumeric. | ||
return asciiAlphanumeric(code) ? nok(code) : ok(code) | ||
return asciiAlphanumeric(code) ? nok(code) : ok(code); | ||
} | ||
@@ -921,12 +836,3 @@ } | ||
function previousWww(code) { | ||
return ( | ||
code === null || | ||
code === 40 || | ||
code === 42 || | ||
code === 95 || | ||
code === 91 || | ||
code === 93 || | ||
code === 126 || | ||
markdownLineEndingOrSpace(code) | ||
) | ||
return code === null || code === 40 || code === 42 || code === 95 || code === 91 || code === 93 || code === 126 || markdownLineEndingOrSpace(code); | ||
} | ||
@@ -941,3 +847,3 @@ | ||
function previousProtocol(code) { | ||
return !asciiAlpha(code) | ||
return !asciiAlpha(code); | ||
} | ||
@@ -954,3 +860,3 @@ | ||
// Other than slash, every preceding character is allowed. | ||
return !(code === 47 || gfmAtext(code)) | ||
return !(code === 47 || gfmAtext(code)); | ||
} | ||
@@ -963,9 +869,3 @@ | ||
function gfmAtext(code) { | ||
return ( | ||
code === 43 || | ||
code === 45 || | ||
code === 46 || | ||
code === 95 || | ||
asciiAlphanumeric(code) | ||
) | ||
return code === 43 || code === 45 || code === 46 || code === 95 || asciiAlphanumeric(code); | ||
} | ||
@@ -978,12 +878,9 @@ | ||
function previousUnbalanced(events) { | ||
let index = events.length | ||
let result = false | ||
let index = events.length; | ||
let result = false; | ||
while (index--) { | ||
const token = events[index][1] | ||
if ( | ||
(token.type === 'labelLink' || token.type === 'labelImage') && | ||
!token._balanced | ||
) { | ||
result = true | ||
break | ||
const token = events[index][1]; | ||
if ((token.type === 'labelLink' || token.type === 'labelImage') && !token._balanced) { | ||
result = true; | ||
break; | ||
} | ||
@@ -994,4 +891,4 @@ | ||
if (token._gfmAutolinkLiteralWalkedInto) { | ||
result = false | ||
break | ||
result = false; | ||
break; | ||
} | ||
@@ -1002,5 +899,5 @@ } | ||
// anything. | ||
events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true | ||
events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true; | ||
} | ||
return result | ||
} | ||
return result; | ||
} |
{ | ||
"name": "micromark-extension-gfm-autolink-literal", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "micromark extension to support GFM autolink literals", | ||
@@ -48,13 +48,13 @@ "license": "MIT", | ||
"@types/node": "^20.0.0", | ||
"c8": "^8.0.0", | ||
"c8": "^10.0.0", | ||
"create-gfm-fixtures": "^1.0.0", | ||
"micromark": "^4.0.0", | ||
"micromark-build": "^2.0.0", | ||
"prettier": "^2.0.0", | ||
"rehype": "^12.0.0", | ||
"remark-cli": "^11.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"prettier": "^3.0.0", | ||
"rehype": "^13.0.0", | ||
"remark-cli": "^12.0.0", | ||
"remark-preset-wooorm": "^10.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^5.0.0", | ||
"xo": "^0.54.0" | ||
"xo": "^0.58.0" | ||
}, | ||
@@ -64,3 +64,3 @@ "scripts": { | ||
"build": "tsc --build --clean && tsc --build && type-coverage && micromark-build", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", | ||
"test-api-prod": "node --conditions production test/index.js", | ||
@@ -95,3 +95,5 @@ "test-api-dev": "node --conditions development test/index.js", | ||
"complexity": "off", | ||
"unicorn/no-this-assignment": "off" | ||
"unicorn/no-this-assignment": "off", | ||
"unicorn/prefer-at": "off", | ||
"unicorn/prefer-string-replace-all": "off" | ||
}, | ||
@@ -98,0 +100,0 @@ "overrides": [ |
@@ -15,20 +15,20 @@ # micromark-extension-gfm-autolink-literal | ||
* [What is this?](#what-is-this) | ||
* [When to use this](#when-to-use-this) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`gfmAutolinkLiteral()`](#gfmautolinkliteral) | ||
* [`gfmAutolinkLiteralHtml()`](#gfmautolinkliteralhtml) | ||
* [Bugs](#bugs) | ||
* [Authoring](#authoring) | ||
* [HTML](#html) | ||
* [CSS](#css) | ||
* [Syntax](#syntax) | ||
* [Types](#types) | ||
* [Compatibility](#compatibility) | ||
* [Security](#security) | ||
* [Related](#related) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
* [What is this?](#what-is-this) | ||
* [When to use this](#when-to-use-this) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`gfmAutolinkLiteral()`](#gfmautolinkliteral) | ||
* [`gfmAutolinkLiteralHtml()`](#gfmautolinkliteralhtml) | ||
* [Bugs](#bugs) | ||
* [Authoring](#authoring) | ||
* [HTML](#html) | ||
* [CSS](#css) | ||
* [Syntax](#syntax) | ||
* [Types](#types) | ||
* [Compatibility](#compatibility) | ||
* [Security](#security) | ||
* [Related](#related) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
@@ -156,11 +156,11 @@ ## What is this? | ||
* [GFM autolink extension (`www.`, `https?://` parts): links don’t work when | ||
after bracket](https://github.com/github/cmark-gfm/issues/278)\ | ||
fixed here ✅ | ||
* [GFM autolink extension (`www.` part): uppercase does not match on | ||
issues/PRs/comments](https://github.com/github/cmark-gfm/issues/280)\ | ||
fixed here ✅ | ||
* [GFM autolink extension (`www.` part): the word `www` | ||
matches](https://github.com/github/cmark-gfm/issues/279)\ | ||
present here for consistency | ||
* [GFM autolink extension (`www.`, `https?://` parts): links don’t work when | ||
after bracket](https://github.com/github/cmark-gfm/issues/278)\ | ||
fixed here ✅ | ||
* [GFM autolink extension (`www.` part): uppercase does not match on | ||
issues/PRs/comments](https://github.com/github/cmark-gfm/issues/280)\ | ||
fixed here ✅ | ||
* [GFM autolink extension (`www.` part): the word `www` | ||
matches](https://github.com/github/cmark-gfm/issues/279)\ | ||
present here for consistency | ||
@@ -327,10 +327,10 @@ ## Authoring | ||
* [`micromark-extension-gfm`][micromark-extension-gfm] | ||
— support all of GFM | ||
* [`mdast-util-gfm-autolink-literal`][mdast-util-gfm-autolink-literal] | ||
— support all of GFM in mdast | ||
* [`mdast-util-gfm`][mdast-util-gfm] | ||
— support all of GFM in mdast | ||
* [`remark-gfm`][remark-gfm] | ||
— support all of GFM in remark | ||
* [`micromark-extension-gfm`][micromark-extension-gfm] | ||
— support all of GFM | ||
* [`mdast-util-gfm-autolink-literal`][mdast-util-gfm-autolink-literal] | ||
— support all of GFM in mdast | ||
* [`mdast-util-gfm`][mdast-util-gfm] | ||
— support all of GFM in mdast | ||
* [`remark-gfm`][remark-gfm] | ||
— support all of GFM in remark | ||
@@ -337,0 +337,0 @@ ## Contribute |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65381
1879