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

When headingStyle is linebreak / hashify header elements (h[1-6]) are remained as it is.. #5

Open
gs-kgopi opened this issue May 2, 2017 · 3 comments

Comments

@gs-kgopi
Copy link

gs-kgopi commented May 2, 2017

Issue: If styleConfig: headingStyle = 'linebreak' || 'hashify', header elements are not getting processed i.e elements remains as it is.

Content used: https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics

Code: htmlToPlainText(plainText.html(), {headingStyle: 'linebreak'});

Reason I found: The corresponding regular expressions are not matching the header elements.

@stubendek
Copy link
Member

Hi!
Will check it, thank you for the issue!

Attila

@gs-kgopi
Copy link
Author

gs-kgopi commented May 2, 2017

Hi @stubendek ..
I have fixed the issue, but not able to push the code due to lack of permissions.

Fix i given;
Changed the regular expression used to match header elements

        // handle headings
	if(headingStyle === "linebreak") {
		tmp = tmp.replace(/<h([1-6])[^>]*>(((?!<\/h\1>).)*)<\/h\1>/gi, function(str, p1, p2) {
			return "\n" + p2 + "\n";
		});
	}

       else if(headingStyle === "hashify") {
		tmp = tmp.replace(/<h([1-6])[^>]*>(((?!<\/h\1>).)*)<\/h\1>/gi, function(str, p1, p2) {
			return "\n&nbsp;\n" + populateChar("#", p1) + " " + p2 + "\n&nbsp;\n";
		});
	}

@Grawl
Copy link

Grawl commented Jun 14, 2021

everyone can use this fix by installing my fork: yarn add Grawl/textversionjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants