Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdast-util-to-hast

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-to-hast - npm Package Compare versions

Comparing version 5.0.0 to 6.0.0

24

lib/footer.js

@@ -10,4 +10,5 @@ 'use strict'

function generateFootnotes(h) {
var footnotes = h.footnotes
var length = footnotes.length
var footnoteById = h.footnoteById
var footnoteOrder = h.footnoteOrder
var length = footnoteOrder.length
var index = -1

@@ -20,8 +21,9 @@ var listItems = []

if (!length) {
return null
}
while (++index < length) {
def = footnoteById[footnoteOrder[index].toUpperCase()]
while (++index < length) {
def = footnotes[index]
if (!def) {
continue
}
content = def.children.concat()

@@ -43,3 +45,3 @@ tail = content[content.length - 1]

listItems[index] = {
listItems.push({
type: 'listItem',

@@ -49,5 +51,9 @@ data: {hProperties: {id: 'fn-' + def.identifier}},

position: def.position
}
})
}
if (listItems.length === 0) {
return null
}
return h(

@@ -54,0 +60,0 @@ null,

@@ -8,4 +8,9 @@ 'use strict'

function footnoteReference(h, node) {
var footnoteOrder = h.footnoteOrder
var identifier = node.identifier
if (footnoteOrder.indexOf(identifier) === -1) {
footnoteOrder.push(identifier)
}
return h(node.position, 'sup', {id: 'fnref-' + identifier}, [

@@ -12,0 +17,0 @@ h(node, 'a', {href: '#fn-' + identifier, className: ['footnote-ref']}, [

@@ -8,13 +8,7 @@ 'use strict'

function footnote(h, node) {
var identifiers = []
var footnoteById = h.footnoteById
var footnoteOrder = h.footnoteOrder
var identifier = 1
var footnotes = h.footnotes
var length = footnotes.length
var index = -1
while (++index < length) {
identifiers[index] = footnotes[index].identifier
}
while (identifiers.indexOf(String(identifier)) !== -1) {
while (identifier in footnoteById) {
identifier++

@@ -25,3 +19,6 @@ }

footnotes.push({
// No need to check if `identifier` exists, as it’s guaranteed to not exist.
footnoteOrder.push(identifier)
footnoteById[identifier] = {
type: 'footnoteDefinition',

@@ -31,3 +28,3 @@ identifier: identifier,

position: node.position
})
}

@@ -34,0 +31,0 @@ return footnoteReference(h, {

@@ -15,2 +15,4 @@ 'use strict'

var own = {}.hasOwnProperty
// Factory to transform.

@@ -20,10 +22,12 @@ function factory(tree, options) {

var dangerous = settings.allowDangerousHTML
var footnoteById = {}
h.dangerous = dangerous
h.definition = definitions(tree, settings)
h.footnotes = []
h.footnoteById = footnoteById
h.footnoteOrder = []
h.augment = augment
h.handlers = xtend(handlers, settings.handlers || {})
visit(tree, 'footnoteDefinition', visitor)
visit(tree, 'footnoteDefinition', onfootnotedefinition)

@@ -85,4 +89,10 @@ return h

function visitor(definition) {
h.footnotes.push(definition)
function onfootnotedefinition(definition) {
var id = definition.identifier.toUpperCase()
// Mimick CM behavior of link definitions.
// https://github.com/syntax-tree/mdast-util-definitions/blob/8d48e57/index.js#L26
if (!own.call(footnoteById, id)) {
footnoteById[id] = definition
}
}

@@ -95,6 +105,6 @@ }

var node = one(h, tree)
var footnotes = footer(h)
var foot = footer(h)
if (node && node.children && footnotes) {
node.children = node.children.concat(u('text', '\n'), footnotes)
if (foot) {
node.children = node.children.concat(u('text', '\n'), foot)
}

@@ -101,0 +111,0 @@

{
"name": "mdast-util-to-hast",
"version": "5.0.0",
"version": "6.0.0",
"description": "Transform mdast to hast",

@@ -5,0 +5,0 @@ "license": "MIT",

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