Skip to content

Commit

Permalink
Move changes to branch bugfix/textbox-overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
joemoongit committed Aug 27, 2024
1 parent 771aaf6 commit fc2a347
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
11 changes: 4 additions & 7 deletions lib/recipe/htmlToTextObjects.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const DOMParser = require("@xmldom/xmldom").DOMParser;

exports.htmlToTextObjects = function (htmlCodes, options = {}) {
exports.htmlToTextObjects = function (htmlCodes) {
htmlCodes = htmlCodes.replace(/<br\/?>/g, "<p>[@@DONOT_RENDER_THIS@@]</p>");
const nodes = new DOMParser().parseFromString(
`<html>${htmlCodes}</html>`,
"text/html"
);
const textObjects = parseNode(nodes, options).childs[0].childs;
const textObjects = parseNode(nodes).childs[0].childs;
return textObjects;
};

Expand Down Expand Up @@ -40,7 +40,7 @@ function isItalicTag(tagName = "") {
return italicTags.includes(tagName);
}

function parseNode(node, options) {
function parseNode(node) {
const attributes = [];
const styles = {};
for (let i in node.attributes) {
Expand Down Expand Up @@ -82,22 +82,19 @@ function parseNode(node, options) {
const parsedData = {
value,
tag: node.tagName,
font: options.font,
isBold: isBoldTag(node.tagName),
isItalic: isItalicTag(node.tagName),
underline: node.tagName == "u",
strikeOut: node.tagName == "del",
attributes,
styles,
needsLineBreaker: needsLineBreaker(node.tagName),
size: options.size,
sizeRatio: getFontSizeRatio(node.tagName),
sizeRatios: [getFontSizeRatio(node.tagName)],
link: node.tagName == "a" ? node.attributes[0].value : null,
childs: [],
};
for (let num in node.childNodes) {
parsedData.childs.push(parseNode(node.childNodes[num], options));
parsedData.childs.push(parseNode(node.childNodes[num]));
}
const ignoreValue = ["\n", "\n\n"];
parsedData.childs = parsedData.childs.filter((item) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/recipe/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ exports._makeTextBox = function _makeTextBox(options) {
* @param {Object|Boolean} [options.highlight] - Text markup annotation.
* @param {Object|Boolean} [options.underline] - Text markup annotation.
* @param {Object|Boolean} [options.strikeOut] - Text markup annotation.
* @param {Boolean} [options.html] - Interpret text as html
* @param {Boolean} [options.flow=false] - Used to activate/deactivate text flow which is the
* ability to use multiple calls to 'text' to create an overall text box.
* @param {number|string} [options.layout] - An identifier of the layout to be associated with given text.
Expand Down Expand Up @@ -275,7 +274,7 @@ exports.text = function text(text = "", x, y, options = {}) {
this._textOptions = this._flow ? options : { textBox: {} };

const textObjects = options.html
? htmlToTextObjects(text, options)
? htmlToTextObjects(text)
: this._makeTextObject(text, pathOptions.size, options);
const textBox = this._makeTextBox(options);

Expand Down
1 change: 0 additions & 1 deletion muhammara.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,6 @@ declare module "muhammara" {
highlight?: boolean;
underline?: boolean;
strikeOut?: boolean;
html?: boolean;
hilite?:
| boolean
| {
Expand Down

0 comments on commit fc2a347

Please sign in to comment.