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

Makes sure the title does not include HTML #34

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"dependencies": {
"html-entities": "^1.2.1",
"lodash": "^4.17.19"
"lodash": "^4.17.19",
"jsdom": "^16.2.2"
}
}
5 changes: 5 additions & 0 deletions src/Tags/PageTitle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const BaseTag = require("./BaseTag");
const jsdom = require("jsdom");

class PageTitle extends BaseTag {
render(title, pageNumber, size) {
Expand All @@ -8,6 +9,10 @@ class PageTitle extends BaseTag {

// Fallback on `title` in config if no title is set for the page.
let pageTitle = title || this.siteTitle;

// Strip any HTML in the title
const dom = new jsdom.JSDOM(`<!DOCTYPE html><h1>${pageTitle}</h1>`);
pageTitle = dom.window.document.querySelector("h1").textContent;

// Showing page numbers?
const showPages = this.showPageNumbers();
Expand Down