File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import bbob from "@bbob/core";
22import { render } from "@bbob/html" ;
33import { lineBreakPlugin } from "./plugins/lineBreak" ;
44import { preserveWhitespace } from "./plugins/preserveWhitespace" ;
5+ import { removeEmptyLinePlugin } from "./plugins/removeEmptyLinesInAttr" ;
56import { availableTags , preset , preventParsing } from "./preset" ;
67import { postprocess } from "./utils/postprocess" ;
78import { preprocessRaw } from "./utils/preprocess" ;
@@ -25,7 +26,7 @@ export const RpNBBCode = (code, opts) => {
2526 if ( opts . preserveWhitespace ) {
2627 plugins . push ( preserveWhitespace ( ) ) ;
2728 }
28- plugins . push ( lineBreakPlugin ( ) ) ;
29+ plugins . push ( lineBreakPlugin ( ) , removeEmptyLinePlugin ( ) ) ;
2930 const [ preprocessed , preprocessedData ] = preprocessRaw ( code ) ;
3031 return bbob ( plugins ) . process ( preprocessed , {
3132 render,
Original file line number Diff line number Diff line change 1+ import { isTagNode } from "@bbob/plugin-helper" ;
2+ const CONSECUTIVE_NEWLINE_REGEX = / \n { 2 , } / gm;
3+
4+ /**
5+ * Removes empty lines from a string
6+ * @param {string } text
7+ */
8+ const removeEmptyLines = ( text ) => {
9+ return text . replace ( CONSECUTIVE_NEWLINE_REGEX , "\n" ) ;
10+ } ;
11+
12+ /**
13+ * Removes empty lines from attributes
14+ * @type {import('@bbob/types').BBobPluginFunction }
15+ */
16+ export const removeEmptyLinePlugin = ( tree ) => {
17+ return tree . walk ( ( node ) => {
18+ if ( isTagNode ( node ) && node . attrs ) {
19+ Object . keys ( node . attrs ) . forEach ( ( key ) => {
20+ if ( typeof node . attrs [ key ] === "string" ) {
21+ node . attrs [ key ] = removeEmptyLines ( node . attrs [ key ] ) ;
22+ }
23+ } ) ;
24+ }
25+ return node ;
26+ } ) ;
27+ } ;
You can’t perform that action at this time.
0 commit comments