Socket
Socket
Sign inDemoInstall

micromark-core-commonmark

Package Overview
Dependencies
29
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-alpha.2 to 1.0.0-alpha.3

53

dev/lib/code-fenced.js

@@ -30,2 +30,4 @@ /**

const closingFenceConstruct = {tokenize: tokenizeClosingFence, partial: true}
/** @type {Construct} */
const nonLazyLine = {tokenize: tokenizeNonLazyLine, partial: true}
const tail = this.events[this.events.length - 1]

@@ -120,7 +122,7 @@ const initialPrefix =

effects.exit(types.codeFencedFence)
return self.interrupt ? ok(code) : content(code)
return self.interrupt ? ok(code) : contentStart(code)
}
/** @type {State} */
function content(code) {
function contentStart(code) {
if (code === codes.eof) {

@@ -131,12 +133,18 @@ return after(code)

if (markdownLineEnding(code)) {
effects.enter(types.lineEnding)
effects.consume(code)
effects.exit(types.lineEnding)
return effects.attempt(
closingFenceConstruct,
after,
initialPrefix
? factorySpace(effects, content, types.linePrefix, initialPrefix + 1)
: content
)
nonLazyLine,
effects.attempt(
closingFenceConstruct,
after,
initialPrefix
? factorySpace(
effects,
contentStart,
types.linePrefix,
initialPrefix + 1
)
: contentStart
),
after
)(code)
}

@@ -152,3 +160,3 @@

effects.exit(types.codeFlowValue)
return content(code)
return contentStart(code)
}

@@ -167,2 +175,23 @@

/** @type {Tokenizer} */
function tokenizeNonLazyLine(effects, ok, nok) {
const self = this
return start
/** @type {State} */
function start(code) {
assert(markdownLineEnding(code), 'expected eol')
effects.enter(types.lineEnding)
effects.consume(code)
effects.exit(types.lineEnding)
return lineStart
}
/** @type {State} */
function lineStart(code) {
return self.parser.lazy[self.now().line] ? nok(code) : ok(code)
}
}
/** @type {Tokenizer} */
function tokenizeClosingFence(effects, ok, nok) {

@@ -169,0 +198,0 @@ let size = 0

@@ -11,3 +11,2 @@ /**

import {markdownLineEnding} from 'micromark-util-character'
import {splice} from 'micromark-util-chunked'
import {codes} from 'micromark-util-symbol/codes.js'

@@ -20,39 +19,42 @@ import {constants} from 'micromark-util-symbol/constants.js'

name: 'codeIndented',
tokenize: tokenizeCodeIndented,
resolve: resolveCodeIndented
tokenize: tokenizeCodeIndented
}
/** @type {Construct} */
const indentedContentConstruct = {
tokenize: tokenizeIndentedContent,
partial: true
}
const indentedContent = {tokenize: tokenizeIndentedContent, partial: true}
/** @type {Resolver} */
function resolveCodeIndented(events, context) {
/** @type {Token} */
const code = {
type: types.codeIndented,
start: events[0][1].start,
end: events[events.length - 1][1].end
}
splice(events, 0, 0, [['enter', code, context]])
splice(events, events.length, 0, [['exit', code, context]])
return events
}
/** @type {Tokenizer} */
function tokenizeCodeIndented(effects, ok, nok) {
return effects.attempt(indentedContentConstruct, afterPrefix, nok)
const self = this
return start
/** @type {State} */
function start(code) {
effects.enter(types.codeIndented)
return factorySpace(
effects,
afterStartPrefix,
types.linePrefix,
constants.tabSize + 1
)(code)
}
/** @type {State} */
function afterStartPrefix(code) {
const tail = self.events[self.events.length - 1]
return tail &&
tail[1].type === types.linePrefix &&
tail[2].sliceSerialize(tail[1], true).length >= constants.tabSize
? afterPrefix(code)
: nok(code)
}
/** @type {State} */
function afterPrefix(code) {
if (code === codes.eof) {
return ok(code)
return after(code)
}
if (markdownLineEnding(code)) {
return effects.attempt(indentedContentConstruct, afterPrefix, ok)(code)
return effects.attempt(indentedContent, afterPrefix, after)(code)
}

@@ -74,2 +76,8 @@

}
/** @type {State} */
function after(code) {
effects.exit(types.codeIndented)
return ok(code)
}
}

@@ -81,11 +89,11 @@

return factorySpace(
effects,
afterPrefix,
types.linePrefix,
constants.tabSize + 1
)
return start
/** @type {State} */
function afterPrefix(code) {
function start(code) {
// If this is a lazy line, it can’t be code.
if (self.parser.lazy[self.now().line]) {
return nok(code)
}
if (markdownLineEnding(code)) {

@@ -95,12 +103,16 @@ effects.enter(types.lineEnding)

effects.exit(types.lineEnding)
return factorySpace(
effects,
afterPrefix,
types.linePrefix,
constants.tabSize + 1
)
return start
}
return factorySpace(
effects,
afterPrefix,
types.linePrefix,
constants.tabSize + 1
)(code)
}
/** @type {State} */
function afterPrefix(code) {
const tail = self.events[self.events.length - 1]
return tail &&

@@ -110,4 +122,6 @@ tail[1].type === types.linePrefix &&

? ok(code)
: markdownLineEnding(code)
? start(code)
: nok(code)
}
}
/**
* No name because it must not be turned off.
*
* @type {Construct}

@@ -5,0 +4,0 @@ */

@@ -19,11 +19,5 @@ /**

* No name because it must not be turned off.
*
* @type {Construct}
*/
export const content = {
tokenize: tokenizeContent,
resolve: resolveContent,
interruptible: true,
lazy: true
}
export const content = {tokenize: tokenizeContent, resolve: resolveContent}

@@ -30,0 +24,0 @@ /** @type {Construct} */

@@ -203,4 +203,4 @@ /**

kind = constants.htmlComplete
// Do not support complete HTML when interrupting.
return self.interrupt
// Do not support complete HTML when interrupting
return self.interrupt && !self.parser.lazy[self.now().line]
? nok(code)

@@ -447,10 +447,30 @@ : startTag

if (markdownLineEnding(code)) {
return effects.attempt(
{tokenize: htmlLineEnd, partial: true},
htmlContinueStart,
done
)(code)
}
effects.enter(types.htmlFlowData)
return continuation(code)
}
/** @type {Tokenizer} */
function htmlLineEnd(effects, ok, nok) {
return start
/** @type {State} */
function start(code) {
assert(markdownLineEnding(code), 'expected eol')
effects.enter(types.lineEnding)
effects.consume(code)
effects.exit(types.lineEnding)
return htmlContinueStart
return lineStart
}
effects.enter(types.htmlFlowData)
return continuation(code)
/** @type {State} */
function lineStart(code) {
return self.parser.lazy[self.now().line] ? nok(code) : ok(code)
}
}

@@ -457,0 +477,0 @@

@@ -118,3 +118,3 @@ /**

if (!self.lazy && (self.interrupt || paragraph)) {
if (!self.parser.lazy[self.now().line] && (self.interrupt || paragraph)) {
effects.enter(types.setextHeadingLine)

@@ -121,0 +121,0 @@ effects.enter(types.setextHeadingLineSequence)

@@ -29,2 +29,8 @@ /**

}
/** @type {Construct} */
const nonLazyLine = {
tokenize: tokenizeNonLazyLine,
partial: true
}
const tail = this.events[this.events.length - 1]

@@ -119,7 +125,7 @@ const initialPrefix =

effects.exit('codeFencedFence')
return self.interrupt ? ok(code) : content(code)
return self.interrupt ? ok(code) : contentStart(code)
}
/** @type {State} */
function content(code) {
function contentStart(code) {
if (code === null) {

@@ -130,12 +136,18 @@ return after(code)

if (markdownLineEnding(code)) {
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
return effects.attempt(
closingFenceConstruct,
after,
initialPrefix
? factorySpace(effects, content, 'linePrefix', initialPrefix + 1)
: content
)
nonLazyLine,
effects.attempt(
closingFenceConstruct,
after,
initialPrefix
? factorySpace(
effects,
contentStart,
'linePrefix',
initialPrefix + 1
)
: contentStart
),
after
)(code)
}

@@ -151,3 +163,3 @@

effects.exit('codeFlowValue')
return content(code)
return contentStart(code)
}

@@ -166,2 +178,21 @@

function tokenizeNonLazyLine(effects, ok, nok) {
const self = this
return start
/** @type {State} */
function start(code) {
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
return lineStart
}
/** @type {State} */
function lineStart(code) {
return self.parser.lazy[self.now().line] ? nok(code) : ok(code)
}
}
/** @type {Tokenizer} */
function tokenizeClosingFence(effects, ok, nok) {

@@ -168,0 +199,0 @@ let size = 0

@@ -10,3 +10,2 @@ /**

import {markdownLineEnding} from 'micromark-util-character'
import {splice} from 'micromark-util-chunked'

@@ -16,37 +15,40 @@ /** @type {Construct} */

name: 'codeIndented',
tokenize: tokenizeCodeIndented,
resolve: resolveCodeIndented
tokenize: tokenizeCodeIndented
}
/** @type {Construct} */
const indentedContentConstruct = {
const indentedContent = {
tokenize: tokenizeIndentedContent,
partial: true
}
/** @type {Resolver} */
function resolveCodeIndented(events, context) {
/** @type {Token} */
const code = {
type: 'codeIndented',
start: events[0][1].start,
end: events[events.length - 1][1].end
}
splice(events, 0, 0, [['enter', code, context]])
splice(events, events.length, 0, [['exit', code, context]])
return events
}
/** @type {Tokenizer} */
function tokenizeCodeIndented(effects, ok, nok) {
return effects.attempt(indentedContentConstruct, afterPrefix, nok)
const self = this
return start
/** @type {State} */
function start(code) {
effects.enter('codeIndented')
return factorySpace(effects, afterStartPrefix, 'linePrefix', 4 + 1)(code)
}
/** @type {State} */
function afterStartPrefix(code) {
const tail = self.events[self.events.length - 1]
return tail &&
tail[1].type === 'linePrefix' &&
tail[2].sliceSerialize(tail[1], true).length >= 4
? afterPrefix(code)
: nok(code)
}
/** @type {State} */
function afterPrefix(code) {
if (code === null) {
return ok(code)
return after(code)
}
if (markdownLineEnding(code)) {
return effects.attempt(indentedContentConstruct, afterPrefix, ok)(code)
return effects.attempt(indentedContent, afterPrefix, after)(code)
}

@@ -68,2 +70,8 @@

}
/** @type {State} */
function after(code) {
effects.exit('codeIndented')
return ok(code)
}
}

@@ -74,6 +82,11 @@ /** @type {Tokenizer} */

const self = this
return factorySpace(effects, afterPrefix, 'linePrefix', 4 + 1)
return start
/** @type {State} */
function afterPrefix(code) {
function start(code) {
// If this is a lazy line, it can’t be code.
if (self.parser.lazy[self.now().line]) {
return nok(code)
}
if (markdownLineEnding(code)) {

@@ -83,5 +96,10 @@ effects.enter('lineEnding')

effects.exit('lineEnding')
return factorySpace(effects, afterPrefix, 'linePrefix', 4 + 1)
return start
}
return factorySpace(effects, afterPrefix, 'linePrefix', 4 + 1)(code)
}
/** @type {State} */
function afterPrefix(code) {
const tail = self.events[self.events.length - 1]

@@ -92,4 +110,6 @@ return tail &&

? ok(code)
: markdownLineEnding(code)
? start(code)
: nok(code)
}
}
/**
* No name because it must not be turned off.
*
* @type {Construct}

@@ -5,0 +4,0 @@ */

@@ -14,3 +14,2 @@ /**

* No name because it must not be turned off.
*
* @type {Construct}

@@ -20,5 +19,3 @@ */

tokenize: tokenizeContent,
resolve: resolveContent,
interruptible: true,
lazy: true
resolve: resolveContent
}

@@ -25,0 +22,0 @@ /** @type {Construct} */

@@ -200,5 +200,5 @@ /**

kind = 7 // Do not support complete HTML when interrupting.
kind = 7 // Do not support complete HTML when interrupting
return self.interrupt
return self.interrupt && !self.parser.lazy[self.now().line]
? nok(code)

@@ -438,10 +438,32 @@ : startTag

if (markdownLineEnding(code)) {
return effects.attempt(
{
tokenize: htmlLineEnd,
partial: true
},
htmlContinueStart,
done
)(code)
}
effects.enter('htmlFlowData')
return continuation(code)
}
/** @type {Tokenizer} */
function htmlLineEnd(effects, ok, nok) {
return start
/** @type {State} */
function start(code) {
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
return htmlContinueStart
return lineStart
}
/** @type {State} */
effects.enter('htmlFlowData')
return continuation(code)
function lineStart(code) {
return self.parser.lazy[self.now().line] ? nok(code) : ok(code)
}
}

@@ -448,0 +470,0 @@ /** @type {State} */

@@ -104,3 +104,3 @@ /**

function start(code) {
if (!self.lazy && (self.interrupt || paragraph)) {
if (!self.parser.lazy[self.now().line] && (self.interrupt || paragraph)) {
effects.enter('setextHeadingLine')

@@ -107,0 +107,0 @@ effects.enter('setextHeadingLineSequence')

{
"name": "micromark-core-commonmark",
"version": "1.0.0-alpha.2",
"version": "1.0.0-alpha.3",
"description": "The CommonMark markdown constructs",

@@ -43,16 +43,16 @@ "license": "MIT",

"parse-entities": "^3.0.0",
"micromark-factory-destination": "^1.0.0-alpha.2",
"micromark-factory-label": "^1.0.0-alpha.2",
"micromark-factory-space": "^1.0.0-alpha.2",
"micromark-factory-title": "^1.0.0-alpha.2",
"micromark-factory-whitespace": "^1.0.0-alpha.2",
"micromark-util-character": "^1.0.0-alpha.2",
"micromark-util-chunked": "^1.0.0-alpha.2",
"micromark-util-classify-character": "^1.0.0-alpha.2",
"micromark-util-html-tag-name": "^1.0.0-alpha.2",
"micromark-util-normalize-identifier": "^1.0.0-alpha.2",
"micromark-util-resolve-all": "^1.0.0-alpha.2",
"micromark-util-subtokenize": "^1.0.0-alpha.2",
"micromark-util-symbol": "^1.0.0-alpha.2",
"micromark-util-types": "1.0.0-alpha.2"
"micromark-factory-destination": "^1.0.0-alpha.3",
"micromark-factory-label": "^1.0.0-alpha.3",
"micromark-factory-space": "^1.0.0-alpha.3",
"micromark-factory-title": "^1.0.0-alpha.3",
"micromark-factory-whitespace": "^1.0.0-alpha.3",
"micromark-util-character": "^1.0.0-alpha.3",
"micromark-util-chunked": "^1.0.0-alpha.3",
"micromark-util-classify-character": "^1.0.0-alpha.3",
"micromark-util-html-tag-name": "^1.0.0-alpha.3",
"micromark-util-normalize-identifier": "^1.0.0-alpha.3",
"micromark-util-resolve-all": "^1.0.0-alpha.3",
"micromark-util-subtokenize": "^1.0.0-alpha.3",
"micromark-util-symbol": "^1.0.0-alpha.3",
"micromark-util-types": "1.0.0-alpha.3"
},

@@ -59,0 +59,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc