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

Bugfix/tw encode speaker notes text #373

Merged
Merged
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
48 changes: 24 additions & 24 deletions dist/pptxgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,8 @@ var PptxGenJS = function(){
strSlideXml += '<p:pic>';
strSlideXml += ' <p:nvPicPr>'
strSlideXml += ' <p:cNvPr id="'+ (idx + 2) +'" name="Object '+ (idx + 1) +'" descr="'+ slideItemObj.image +'">';
if ( slideItemObj.hyperlink && slideItemObj.hyperlink.url ) strSlideXml += '<a:hlinkClick r:id="rId'+ slideItemObj.hyperlink.rId +'" tooltip="'+ (slideItemObj.hyperlink.tooltip ? decodeXmlEntities(slideItemObj.hyperlink.tooltip) : '') +'" />';
if ( slideItemObj.hyperlink && slideItemObj.hyperlink.slide ) strSlideXml += '<a:hlinkClick r:id="rId'+ slideItemObj.hyperlink.rId +'" tooltip="'+ (slideItemObj.hyperlink.tooltip ? decodeXmlEntities(slideItemObj.hyperlink.tooltip) : '') +'" action="ppaction://hlinksldjump" />';
if ( slideItemObj.hyperlink && slideItemObj.hyperlink.url ) strSlideXml += '<a:hlinkClick r:id="rId'+ slideItemObj.hyperlink.rId +'" tooltip="'+ (slideItemObj.hyperlink.tooltip ? encodeXmlEntities(slideItemObj.hyperlink.tooltip) : '') +'" />';
if ( slideItemObj.hyperlink && slideItemObj.hyperlink.slide ) strSlideXml += '<a:hlinkClick r:id="rId'+ slideItemObj.hyperlink.rId +'" tooltip="'+ (slideItemObj.hyperlink.tooltip ? encodeXmlEntities(slideItemObj.hyperlink.tooltip) : '') +'" action="ppaction://hlinksldjump" />';
strSlideXml += ' </p:cNvPr>';
strSlideXml += ' <p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr><p:nvPr/>';
strSlideXml += ' </p:nvPicPr>';
Expand Down Expand Up @@ -1389,18 +1389,18 @@ var PptxGenJS = function(){
data.forEach(function(objData,idx){
if ( idx == 0 ) strSharedStrings += '<si><t>'+ 'X-Axis' +'</t></si>';
else {
strSharedStrings += '<si><t>'+ decodeXmlEntities(objData.name || ' ') +'</t></si>';
strSharedStrings += '<si><t>'+ decodeXmlEntities('Size '+idx) +'</t></si>';
strSharedStrings += '<si><t>'+ encodeXmlEntities(objData.name || ' ') +'</t></si>';
strSharedStrings += '<si><t>'+ encodeXmlEntities('Size '+idx) +'</t></si>';
}
});
}
else {
data.forEach(function(objData,idx){ strSharedStrings += '<si><t>'+ decodeXmlEntities((objData.name || ' ').replace('X-Axis','X-Values')) +'</t></si>'; });
data.forEach(function(objData,idx){ strSharedStrings += '<si><t>'+ encodeXmlEntities((objData.name || ' ').replace('X-Axis','X-Values')) +'</t></si>'; });
}

// D: Add `labels`/Categories
if ( chartObject.opts.type.name != 'bubble' && chartObject.opts.type.name != 'scatter' ) {
data[0].labels.forEach(function(label,idx){ strSharedStrings += '<si><t>'+ decodeXmlEntities(label) +'</t></si>'; });
data[0].labels.forEach(function(label,idx){ strSharedStrings += '<si><t>'+ encodeXmlEntities(label) +'</t></si>'; });
}

strSharedStrings += '</sst>\n';
Expand All @@ -1426,7 +1426,7 @@ var PptxGenJS = function(){
strTableXml += '<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="1" name="Table1" displayName="Table1" ref="A1:'+ LETTERS[data.length] + (data[0].labels.length+1) +'" totalsRowShown="0">';
strTableXml += '<tableColumns count="' + (data.length+1) +'">';
strTableXml += '<tableColumn id="1" name=" " />';
data.forEach(function(obj,idx){ strTableXml += '<tableColumn id="'+ (idx+2) +'" name="'+ decodeXmlEntities(obj.name) +'" />' });
data.forEach(function(obj,idx){ strTableXml += '<tableColumn id="'+ (idx+2) +'" name="'+ encodeXmlEntities(obj.name) +'" />' });
}
strTableXml += '</tableColumns>';
strTableXml += '<tableStyleInfo showFirstColumn="0" showLastColumn="0" showRowStripes="1" showColumnStripes="0" />';
Expand Down Expand Up @@ -1996,7 +1996,7 @@ var PptxGenJS = function(){
/**
* DESC: Replace special XML characters with HTML-encoded strings
*/
function decodeXmlEntities(inStr) {
function encodeXmlEntities(inStr) {
// NOTE: Dont use short-circuit eval here as value c/b "0" (zero) etc.!
if ( typeof inStr === 'undefined' || inStr == null ) return "";
return inStr.toString().replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/\'/g,'&apos;');
Expand Down Expand Up @@ -2655,7 +2655,7 @@ var PptxGenJS = function(){
strXml += ' <c:tx>';
strXml += ' <c:strRef>';
strXml += ' <c:f>Sheet1!$'+ getExcelColName(idx+1) +'$1</c:f>';
strXml += ' <c:strCache><c:ptCount val="1"/><c:pt idx="0"><c:v>'+ decodeXmlEntities(obj.name) +'</c:v></c:pt></c:strCache>';
strXml += ' <c:strCache><c:ptCount val="1"/><c:pt idx="0"><c:v>'+ encodeXmlEntities(obj.name) +'</c:v></c:pt></c:strCache>';
strXml += ' </c:strRef>';
strXml += ' </c:tx>';

Expand Down Expand Up @@ -2751,7 +2751,7 @@ var PptxGenJS = function(){
strXml += ' <c:numCache>';
strXml += ' <c:formatCode>'+ opts.catLabelFormatCode +'</c:formatCode>';
strXml += ' <c:ptCount val="'+ obj.labels.length +'"/>';
obj.labels.forEach(function(label,idx){ strXml += '<c:pt idx="'+ idx +'"><c:v>'+ decodeXmlEntities(label) +'</c:v></c:pt>'; });
obj.labels.forEach(function(label,idx){ strXml += '<c:pt idx="'+ idx +'"><c:v>'+ encodeXmlEntities(label) +'</c:v></c:pt>'; });
strXml += ' </c:numCache>';
strXml += ' </c:numRef>';
}
Expand All @@ -2760,7 +2760,7 @@ var PptxGenJS = function(){
strXml += ' <c:f>Sheet1!'+ '$A$2:$A$'+ (obj.labels.length+1) +'</c:f>';
strXml += ' <c:strCache>';
strXml += ' <c:ptCount val="'+ obj.labels.length +'"/>';
obj.labels.forEach(function(label,idx){ strXml += '<c:pt idx="'+ idx +'"><c:v>'+ decodeXmlEntities(label) +'</c:v></c:pt>'; });
obj.labels.forEach(function(label,idx){ strXml += '<c:pt idx="'+ idx +'"><c:v>'+ encodeXmlEntities(label) +'</c:v></c:pt>'; });
strXml += ' </c:strCache>';
strXml += ' </c:strRef>';
}
Expand Down Expand Up @@ -3179,7 +3179,7 @@ var PptxGenJS = function(){
strXml += ' <c:f>Sheet1!$B$1</c:f>';
strXml += ' <c:strCache>';
strXml += ' <c:ptCount val="1"/>';
strXml += ' <c:pt idx="0"><c:v>'+ decodeXmlEntities(obj.name) +'</c:v></c:pt>';
strXml += ' <c:pt idx="0"><c:v>'+ encodeXmlEntities(obj.name) +'</c:v></c:pt>';
strXml += ' </c:strCache>';
strXml += ' </c:strRef>';
strXml += ' </c:tx>';
Expand Down Expand Up @@ -3264,7 +3264,7 @@ var PptxGenJS = function(){
strXml += ' <c:f>Sheet1!'+ '$A$2:$A$'+ (obj.labels.length+1) +'</c:f>';
strXml += ' <c:strCache>';
strXml += ' <c:ptCount val="'+ obj.labels.length +'"/>';
obj.labels.forEach(function(label,idx){ strXml += '<c:pt idx="'+ idx +'"><c:v>'+ decodeXmlEntities(label) +'</c:v></c:pt>'; });
obj.labels.forEach(function(label,idx){ strXml += '<c:pt idx="'+ idx +'"><c:v>'+ encodeXmlEntities(label) +'</c:v></c:pt>'; });
strXml += ' </c:strCache>';
strXml += ' </c:strRef>';
strXml += '</c:cat>';
Expand Down Expand Up @@ -3481,7 +3481,7 @@ var PptxGenJS = function(){
strXml += ' <a:solidFill><a:srgbClr val="'+ (opts.color || DEF_FONT_COLOR) +'"/></a:solidFill>';
strXml += ' <a:latin typeface="'+ (opts.fontFace || 'Arial') +'"/>';
strXml += ' </a:rPr>';
strXml += ' <a:t>'+ (decodeXmlEntities(opts.title) || '') +'</a:t>';
strXml += ' <a:t>'+ (encodeXmlEntities(opts.title) || '') +'</a:t>';
strXml += ' </a:r>';
strXml += ' </a:p>';
strXml += ' </c:rich>';
Expand Down Expand Up @@ -3787,10 +3787,10 @@ var PptxGenJS = function(){
else if ( opts.hyperlink.url ) {
// FIXME-20170410: FUTURE-FEATURE: color (link is always blue in Keynote and PPT online, so usual text run above isnt honored for links..?)
//startInfo += '<a:uFill>'+ genXmlColorSelection('0000FF') +'</a:uFill>'; // Breaks PPT2010! (Issue#74)
startInfo += '<a:hlinkClick r:id="rId'+ opts.hyperlink.rId +'" invalidUrl="" action="" tgtFrame="" tooltip="'+ (opts.hyperlink.tooltip ? decodeXmlEntities(opts.hyperlink.tooltip) : '') +'" history="1" highlightClick="0" endSnd="0" />';
startInfo += '<a:hlinkClick r:id="rId'+ opts.hyperlink.rId +'" invalidUrl="" action="" tgtFrame="" tooltip="'+ (opts.hyperlink.tooltip ? encodeXmlEntities(opts.hyperlink.tooltip) : '') +'" history="1" highlightClick="0" endSnd="0" />';
}
else if ( opts.hyperlink.slide ) {
startInfo += '<a:hlinkClick r:id="rId'+ opts.hyperlink.rId +'" action="ppaction://hlinksldjump" tooltip="'+ (opts.hyperlink.tooltip ? decodeXmlEntities(opts.hyperlink.tooltip) : '') +'" />';
startInfo += '<a:hlinkClick r:id="rId'+ opts.hyperlink.rId +'" action="ppaction://hlinksldjump" tooltip="'+ (opts.hyperlink.tooltip ? encodeXmlEntities(opts.hyperlink.tooltip) : '') +'" />';
}
}

Expand All @@ -3802,7 +3802,7 @@ var PptxGenJS = function(){
if ( parsedText.length > 1 ) {
var outTextData = '';
for ( var i = 0, total_size_i = parsedText.length; i < total_size_i; i++ ) {
outTextData += '<a:r>' + startInfo+ '<a:t>' + decodeXmlEntities(parsedText[i]);
outTextData += '<a:r>' + startInfo+ '<a:t>' + encodeXmlEntities(parsedText[i]);
// Stop/Start <p>aragraph as long as there is more lines ahead (otherwise its closed at the end of this function)
if ( (i + 1) < total_size_i ) outTextData += (opts.breakLine ? CRLF : '') + '</a:t></a:r>';
}
Expand All @@ -3811,7 +3811,7 @@ var PptxGenJS = function(){
else {
// Handle cases where addText `text` was an array of objects - if a text object doesnt contain a '\n' it still need alignment!
// The first pPr-align is done in makeXml - use line countr to ensure we only add subsequently as needed
xmlTextRun = ( (opts.align && opts.lineIdx > 0) ? paraProp : '') + '<a:r>' + startInfo+ '<a:t>' + decodeXmlEntities(inStrText);
xmlTextRun = ( (opts.align && opts.lineIdx > 0) ? paraProp : '') + '<a:r>' + startInfo+ '<a:t>' + encodeXmlEntities(inStrText);
}

// Return paragraph with text run
Expand Down Expand Up @@ -4016,10 +4016,10 @@ var PptxGenJS = function(){
function makeXmlCore() {
var strXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+CRLF;
strXml += '<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
strXml += '<dc:title>'+ decodeXmlEntities(gObjPptx.title) +'</dc:title>';
strXml += '<dc:subject>'+ decodeXmlEntities(gObjPptx.subject) +'</dc:subject>';
strXml += '<dc:creator>'+ decodeXmlEntities(gObjPptx.author) +'</dc:creator>';
strXml += '<cp:lastModifiedBy>'+ decodeXmlEntities(gObjPptx.author) +'</cp:lastModifiedBy>';
strXml += '<dc:title>'+ encodeXmlEntities(gObjPptx.title) +'</dc:title>';
strXml += '<dc:subject>'+ encodeXmlEntities(gObjPptx.subject) +'</dc:subject>';
strXml += '<dc:creator>'+ encodeXmlEntities(gObjPptx.author) +'</dc:creator>';
strXml += '<cp:lastModifiedBy>'+ encodeXmlEntities(gObjPptx.author) +'</cp:lastModifiedBy>';
strXml += '<cp:revision>'+ gObjPptx.revision +'</cp:revision>';
strXml += '<dcterms:created xsi:type="dcterms:W3CDTF">'+ new Date().toISOString() +'</dcterms:created>';
strXml += '<dcterms:modified xsi:type="dcterms:W3CDTF">'+ new Date().toISOString() +'</dcterms:modified>';
Expand Down Expand Up @@ -4074,7 +4074,7 @@ var PptxGenJS = function(){
notesStr += data.text;
}
});
return notesStr;
return notesStr.replace(/\r*\n/g, CRLF);
}

function makeXmlNotesSlide(objSlide) {
Expand All @@ -4091,7 +4091,7 @@ var PptxGenJS = function(){
+ '<p:ph type="body" idx="1" /></p:nvPr></p:nvSpPr><p:spPr />'
+ '<p:txBody><a:bodyPr /><a:lstStyle /><a:p><a:r>'
+ '<a:rPr lang="en-US" dirty="0" smtClean="0" /><a:t>'
+ getNotesFromSlide(objSlide)
+ encodeXmlEntities(getNotesFromSlide(objSlide))
+ '</a:t></a:r><a:endParaRPr lang="en-US" dirty="0" /></a:p></p:txBody>'
+ '</p:sp><p:sp><p:nvSpPr><p:cNvPr id="4" name="Slide Number Placeholder 3" />'
+ '<p:cNvSpPr><a:spLocks noGrp="1" /></p:cNvSpPr><p:nvPr>'
Expand Down