Socket
Socket
Sign inDemoInstall

shortcode-tree

Package Overview
Dependencies
0
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.4.1

35

dist/shortcode-tree.js

@@ -26,2 +26,3 @@ 'use strict';

/**

@@ -71,5 +72,33 @@ * Traverses a tree node: extracts short codes from the node text, and traverses its child nodes.

},
extractTextContent(input) {
extractTextContent: function extractTextContent(input) {
var treeRootNode = this.parse(input);
var textContent = "";
var fnTraverseNodeForContent = function fnTraverseNodeForContent(node) {
var appendText = null;
if (node instanceof TextNode) {
appendText = node.text;
} else if (node instanceof ShortcodeNode) {
if (node.children.length) {
node.children.forEach(function (node) {
fnTraverseNodeForContent(node);
});
} else {
// Topmost node with no children
appendText = node.text;
}
}
if (appendText && appendText.length) {
if (textContent.length && !textContent.endsWith(' ')) {
textContent += ' ';
}
textContent += appendText;
}
};
fnTraverseNodeForContent(treeRootNode);
return textContent;
}

@@ -76,0 +105,0 @@ };

2

package.json
{
"name": "shortcode-tree",
"version": "1.4.0",
"version": "1.4.1",
"description": "Parser library for reading short codes (BB codes) into a tree structure",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -33,2 +33,3 @@ # shortcode-tree

- Stringify `Shortcode` objects to shortcode text
- Extract only text / HTML from a document containg shortcodes

@@ -188,2 +189,11 @@ ## Installation

The `extractShortcodes` method returns an array of `Shortcode` objects.
The `extractShortcodes` method returns an array of `Shortcode` objects.
### Extracting text/HTML from a shortcode fragment
var treeParser = require('shortcode-tree').ShortcodeTree;
var input = `root [row][column]deep[/column][/row]`;
treeParser.extractTextContent(input);
// returns: "root deep"
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