Skip to content

'&' was breaking the ppt #16

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

Open
wants to merge 3 commits into
base: master
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
Binary file modified examples/example-href.pptx
Binary file not shown.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ LinkModule = (function () {

LinkModule.prototype.getLinkFontSize = function(xmlTemplater, fullTextTag) {
var beforeTheTag = xmlTemplater.content.slice(0, xmlTemplater.content.indexOf(fullTextTag));
beforeTheTag = beforeTheTag.slice(beforeTheTag.lastIndexOf("<a:endParaRPr"));
var beforeTheTag1 = beforeTheTag.slice(beforeTheTag.lastIndexOf("<a:endParaRPr"));
if (beforeTheTag1.length < 5) {
beforeTheTag = beforeTheTag.slice(beforeTheTag.lastIndexOf("lang="));
} else {
beforeTheTag = beforeTheTag1;
}
var indexOfSz = beforeTheTag.indexOf("sz=\"");
if (indexOfSz !== -1 && beforeTheTag.indexOf("extLst") === -1) {
var szRegex = /sz="(\d+)"/;
Expand All @@ -91,6 +96,9 @@ LinkModule = (function () {
LinkModule.prototype.getLinkXml = function(_arg) {
var linkId = _arg.linkID, linkText = _arg.linkText, size = _arg.size;
if (this.linkManager.pptx) {
var replaceRegex = '&';
var replaceWith = '&amp;';
linkText = linkText.replace(new RegExp(replaceRegex, 'g'), replaceWith);
return "</a:t></a:r><a:r><a:rPr " + (size !== -1 ? "sz=\"" + size + "\" " : "") + "lang=\"en-US\" dirty=\"0\" smtClean=\"0\"><a:hlinkClick r:id=\"rId" + linkId + "\"/></a:rPr><a:t>" + linkText + "</a:t></a:r><a:r><a:t>";
}
return "</w:t></w:r><w:hyperlink r:id=\"rId" + linkId + "\" w:history=\"1\"><w:bookmarkStart w:id=\"0\" w:name=\"_GoBack\"/><w:bookmarkEnd w:id=\"0\"/><w:r w:rsidR=\"00052F25\" w:rsidRPr=\"00052F25\"><w:rPr><w:rStyle w:val=\"Hyperlink\"/></w:rPr><w:t>" + linkText + "</w:t></w:r></w:hyperlink><w:r><w:t xml:space=\"preserve\">";
Expand Down
15 changes: 13 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@
link: {
TEXT : "Hakuna matata",
URL : "http://google.com"
},
special_link: {
TEXT : "Hakuna && matata",
URL : "http://google.com"
}
}).render();
zip = out.getZip();
Expand All @@ -279,6 +283,13 @@
relsFileContent = relsFile.asText();
return expect(relsFileContent).to.contain("<a:hlinkClick r:id=\"rId2\"/></a:rPr><a:t>Hakuna matata</a:t>");
});
it('&-sign should be replaced by &amp;', function() { // &amp;
var relsFile, relsFileContent;
relsFile = zip.files['ppt/slides/slide2.xml'];
expect(relsFile != null).to.equal(true);
relsFileContent = relsFile.asText();
return expect(relsFileContent).to.contain("<a:hlinkClick r:id=\"rId4\"/></a:rPr><a:t>Hakuna &amp;&amp; matata</a:t>");
});

it('should create relationship in rels file', function() {
var relsFile, relsFileContent;
Expand Down Expand Up @@ -347,7 +358,7 @@
out = docX[name].load(docX[name].loadedContent).setData({
subsidiaries: [
{
title: "John Smith",
title: "John & Smith",
link: "[email protected]"
}, {
title: "Bill Knott",
Expand All @@ -362,7 +373,7 @@
expect(relsFile != null).to.equal(true);
relsFileContent = relsFile.asText();

expect(relsFileContent).to.contain("<a:t>John Smith Sales for Q1</a:t>");
expect(relsFileContent).to.contain("<a:t>John &amp; Smith Sales for Q1</a:t>");
expect(relsFileContent).to.contain("<a:t>Bill Knott Sales for Q1</a:t>");
expect(relsFileContent).to.contain("<a:hlinkClick r:id=\"rId2\"/></a:rPr><a:t>[email protected]</a:t>");
return expect(relsFileContent).to.contain("<a:hlinkClick r:id=\"rId3\"/></a:rPr><a:t>[email protected]</a:t>");
Expand Down