Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/bundled/bbcode-parser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/bundled/bbcode-parser.min.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion bbcode-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import bbob from "@bbob/core";
import { render } from "@bbob/html";
import { lineBreakPlugin } from "./plugins/lineBreak";
import { preserveWhitespace } from "./plugins/preserveWhitespace";
import { removeEmptyLinePlugin } from "./plugins/removeEmptyLinesInAttr";
import { availableTags, preset, preventParsing } from "./preset";
import { postprocess } from "./utils/postprocess";
import { preprocessRaw } from "./utils/preprocess";
Expand All @@ -25,7 +26,7 @@ export const RpNBBCode = (code, opts) => {
if (opts.preserveWhitespace) {
plugins.push(preserveWhitespace());
}
plugins.push(lineBreakPlugin());
plugins.push(lineBreakPlugin(), removeEmptyLinePlugin);
const [preprocessed, preprocessedData] = preprocessRaw(code);
return bbob(plugins).process(preprocessed, {
render,
Expand Down
28 changes: 28 additions & 0 deletions bbcode-src/plugins/removeEmptyLinesInAttr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { isTagNode } from "@bbob/plugin-helper";

const CONSECUTIVE_NEWLINE_REGEX = /\n{2,}/gm;

/**
* Removes empty lines from a string
* @param {string} text
*/
const removeEmptyLines = (text) => {
return text.replace(CONSECUTIVE_NEWLINE_REGEX, "\n");
};

/**
* Removes empty lines from attributes
* @type {import('@bbob/types').BBobPluginFunction}
*/
export const removeEmptyLinePlugin = (tree) => {
return tree.walk((node) => {
if (isTagNode(node) && node.attrs) {
Object.keys(node.attrs).forEach((key) => {
if (typeof node.attrs[key] === "string") {
node.attrs[key] = removeEmptyLines(node.attrs[key]);
}
});
}
return node;
});
};