Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases for text box underline, strikethrough, and highlight features #311

Merged
merged 3 commits into from
Sep 22, 2024
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
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Tests for bold, italic, underline, strikethrough, and highlights in textboxes

## [5.0.0] - 2024-09-08

### Added
Expand Down Expand Up @@ -50,15 +54,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- Underline in text object
- Recipe type / arg documentation
- Add missing type `userPassword` to `EncryptOptions`
- Underline in text object

### Added

- Strikethrough implementation in text object
- Add electron 23.2., 23.3
- Recipe infos to readme
- Strikethrough implementation in text object
- Electron v24.1, 24.2, 24.3, 24.4, 24.5, 24.6
- Add node 20.x
- Add electron v25.0, 25.1, 25.2, 25.3
Expand Down
11 changes: 7 additions & 4 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) {
exports.htmlToTextObjects = function (htmlCodes, options = {}) {
htmlCodes = htmlCodes.replace(/<br\/?>/g, "<p>[@@DONOT_RENDER_THIS@@]</p>");
const nodes = new DOMParser().parseFromString(
`<html>${htmlCodes}</html>`,
"text/html",
);
const textObjects = parseNode(nodes).childs[0].childs;
const textObjects = parseNode(nodes, options).childs[0].childs;
return textObjects;
};

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

function parseNode(node) {
function parseNode(node, options) {
const attributes = [];
const styles = {};
for (let i in node.attributes) {
Expand Down Expand Up @@ -82,19 +82,22 @@ function parseNode(node) {
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]));
parsedData.childs.push(parseNode(node.childNodes[num], options));
}
const ignoreValue = ["\n", "\n\n"];
parsedData.childs = parsedData.childs.filter((item) => {
Expand Down
3 changes: 2 additions & 1 deletion lib/recipe/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ 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 @@ -274,7 +275,7 @@ exports.text = function text(text = "", x, y, options = {}) {
this._textOptions = this._flow ? options : { textBox: {} };

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

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