postcss-markdown
Advanced tools
Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2
"use strict"; | ||
const remarkParse = require("remark-parse"); | ||
const unified = require("unified"); | ||
const fromMarkdown = require("mdast-util-from-markdown"); | ||
const buildSyntaxResolver = require("../syntax/build-syntax-resolver"); | ||
const remarkParser = unified().use(remarkParse, { | ||
commonmark: true, | ||
}); | ||
function extractStyles(source, opts) { | ||
@@ -16,9 +11,9 @@ const resolveSyntax = buildSyntaxResolver(opts.config); | ||
const ast = remarkParser().parse(source); | ||
const ast = fromMarkdown(source); | ||
const styles = []; | ||
let ignoreState = false; | ||
const ignoreStatus = new Map(); | ||
function addStyle(style) { | ||
if (ignoreState) { | ||
function addStyle(style, parent) { | ||
if (ignoreStatus.get(parent)) { | ||
if (style.isMarkdown || /^<style/iu.test(style.content)) { | ||
@@ -31,3 +26,3 @@ return; | ||
function processBlock(block) { | ||
function processBlock(block, parent) { | ||
/** @type {string | null} */ | ||
@@ -56,12 +51,15 @@ const lang = block.lang; | ||
} | ||
addStyle({ | ||
startIndex, | ||
isMarkdown: true, | ||
content, | ||
lang: lang.toLowerCase(), | ||
syntax, | ||
}); | ||
addStyle( | ||
{ | ||
startIndex, | ||
isMarkdown: true, | ||
content, | ||
lang: lang.toLowerCase(), | ||
syntax, | ||
}, | ||
parent | ||
); | ||
} | ||
function processHtml(node) { | ||
function processHtml(node, parent) { | ||
const syntax = resolveSyntax("html"); | ||
@@ -73,9 +71,12 @@ if (!syntax) { | ||
addStyle({ | ||
startIndex, | ||
isMarkdown: false, | ||
content: source.slice(startIndex, node.position.end.offset), | ||
lang: "html", | ||
syntax, | ||
}); | ||
addStyle( | ||
{ | ||
startIndex, | ||
isMarkdown: false, | ||
content: source.slice(startIndex, node.position.end.offset), | ||
lang: "html", | ||
syntax, | ||
}, | ||
parent | ||
); | ||
} | ||
@@ -92,3 +93,3 @@ | ||
if (commentValue.trim() === "postcss-ignore") { | ||
ignoreState = true; | ||
ignoreStatus.set(parent, true); | ||
return; | ||
@@ -98,3 +99,3 @@ } | ||
if (htmlInMd) { | ||
processHtml(node); | ||
processHtml(node, parent); | ||
} | ||
@@ -104,3 +105,3 @@ } | ||
} | ||
ignoreState = false; | ||
ignoreStatus.delete(parent); | ||
}); | ||
@@ -107,0 +108,0 @@ |
{ | ||
"name": "postcss-markdown", | ||
"version": "1.0.0-alpha.1", | ||
"version": "1.0.0-alpha.2", | ||
"publishConfig": { | ||
@@ -57,6 +57,5 @@ "access": "public", | ||
"dependencies": { | ||
"mdast-util-from-markdown": "^0.8.5", | ||
"postcss": "^8.3.9", | ||
"postcss-safe-parser": "^6.0.0", | ||
"remark-parse": "^9.0.0", | ||
"unified": "^9.2.2" | ||
"postcss-safe-parser": "^6.0.0" | ||
}, | ||
@@ -83,3 +82,3 @@ "devDependencies": { | ||
"postcss-less": "^5.0.0", | ||
"postcss-scss": "^2.0.0", | ||
"postcss-scss": "^4.0.0", | ||
"postcss-styl": "^0.9.0", | ||
@@ -86,0 +85,0 @@ "prettier": "^2.4.1", |
20580
3
511
- Removedremark-parse@^9.0.0
- Removedunified@^9.2.2
- Removedbail@1.0.5(transitive)
- Removedextend@3.0.2(transitive)
- Removedis-buffer@2.0.5(transitive)
- Removedis-plain-obj@2.1.0(transitive)
- Removedremark-parse@9.0.0(transitive)
- Removedtrough@1.0.5(transitive)
- Removedunified@9.2.2(transitive)
- Removedvfile@4.2.1(transitive)
- Removedvfile-message@2.0.4(transitive)