|
@@ -8,10 +8,11 @@ function parseMd(content) {
|
|
|
var isAmpImgRange = false;
|
|
|
var result = [];
|
|
|
|
|
|
- var blocks = new Array();
|
|
|
+ var rblocks = new Array();
|
|
|
lineIdx = 1;
|
|
|
foundImg = false;
|
|
|
foundYT = false;
|
|
|
+ foundTBL = false;
|
|
|
crossLine = "";
|
|
|
|
|
|
for (var line of content.split('\n')) {
|
|
@@ -19,19 +20,19 @@ function parseMd(content) {
|
|
|
if (isNotFrontMatterCount < 2) {
|
|
|
frontMatters.push(line)
|
|
|
if (line.includes('title: ')) {
|
|
|
- $('#ctitle').val(line.replace('title: ','').replaceAll('\"',''));
|
|
|
+ $('#ctitle').val(line.replace('title: ', '').replaceAll('\"', ''));
|
|
|
}
|
|
|
if (line.includes('date: ')) {
|
|
|
//alert(line);
|
|
|
- $('#cdate').val(line.replace('date: ','').replaceAll('\"',''));
|
|
|
+ $('#cdate').val(line.replace('date: ', '').replaceAll('\"', ''));
|
|
|
}
|
|
|
if (line.includes('draft: ')) {
|
|
|
//alert(line);
|
|
|
- $('#cdraft').val(line.replace('draft: ','').replaceAll('\"',''));
|
|
|
- console.log($('#cdraft').val());
|
|
|
+ $('#cdraft').val(line.replace('draft: ', '').replaceAll('\"', ''));
|
|
|
+ //console.log($('#cdraft').val());
|
|
|
$('#cdraft').removeAttr('checked');
|
|
|
- if($('#cdraft').val() == 'false')
|
|
|
- $('#cdraft').prop('checked',true);
|
|
|
+ if ($('#cdraft').val() == 'false')
|
|
|
+ $('#cdraft').prop('checked', true);
|
|
|
/*
|
|
|
if($('#cdraft').val() == 'true')
|
|
|
$('#cdraft').removeAttr('checked');
|
|
@@ -41,27 +42,27 @@ function parseMd(content) {
|
|
|
}
|
|
|
if (line.includes('type: ')) {
|
|
|
//alert(line);
|
|
|
- $('#ctype').val(line.replace('type: ','').replaceAll('\"',''));
|
|
|
+ $('#ctype').val(line.replace('type: ', '').replaceAll('\"', ''));
|
|
|
}
|
|
|
if (line.includes('url: ')) {
|
|
|
//alert(line);
|
|
|
- $('#curl').val(line.replace('url: ','').replaceAll('\"',''));
|
|
|
+ $('#curl').val(line.replace('url: ', '').replaceAll('\"', ''));
|
|
|
}
|
|
|
if (line.includes('image: ')) {
|
|
|
//alert(line);
|
|
|
- $('#cimage').val(line.replace('image: ','').replaceAll('\"',''));
|
|
|
+ $('#cimage').val(line.replace('image: ', '').replaceAll('\"', ''));
|
|
|
}
|
|
|
if (line.includes('description: ')) {
|
|
|
//alert(line);
|
|
|
- $('#cdescription').val(line.replace('description: ','').replaceAll('\"',''));
|
|
|
+ $('#cdescription').val(line.replace('description: ', '').replaceAll('\"', ''));
|
|
|
}
|
|
|
if (line.includes('weight: ')) {
|
|
|
//alert(line);
|
|
|
- $('#cweight').val(line.replace('weight: ','').replaceAll('\"',''));
|
|
|
+ $('#cweight').val(line.replace('weight: ', '').replaceAll('\"', ''));
|
|
|
}
|
|
|
if (line.includes('tag: ')) {
|
|
|
//alert(line);
|
|
|
- $('#ctag').val(line.replace('tag: ','').replaceAll('\"',''));
|
|
|
+ $('#ctag').val(line.replace('tag: ', '').replaceAll('\"', ''));
|
|
|
}
|
|
|
|
|
|
if (line.includes('---')) {
|
|
@@ -70,32 +71,31 @@ function parseMd(content) {
|
|
|
continue;
|
|
|
}
|
|
|
contentMatters.push(line)
|
|
|
-/* if (line.toString().trim() == "") {
|
|
|
- blocks.push({ 'type': 'br', 'text': line });
|
|
|
- continue;
|
|
|
- } */
|
|
|
+ /* if (line.toString().trim() == "") {
|
|
|
+ rblocks.push({ 'type': 'br', 'text': line });
|
|
|
+ continue;
|
|
|
+ } */
|
|
|
|
|
|
if (line.includes('---')) {
|
|
|
- blocks.push({ 'type': 'hr', 'text': line });
|
|
|
+ rblocks.push({ 'type': 'hr', 'text': line });
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if (line.includes('###')) {
|
|
|
- blocks.push({ 'type': 'title', 'text': line });
|
|
|
+ rblocks.push({ 'type': 'title', 'text': line });
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if (line.includes('{{% chuz-div class=\"mt-5\" %}}')) {
|
|
|
- blocks.push({ 'type': 'mt5', 'text': line });
|
|
|
+ rblocks.push({ 'type': 'mt5', 'text': line });
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if (line.includes('<amp-img') || foundImg) {
|
|
|
crossLine += line;
|
|
|
foundImg = true;
|
|
|
- if (line.includes('</amp-img>'))
|
|
|
- {
|
|
|
- blocks.push({ 'type': 'img', 'text': crossLine });
|
|
|
+ if (line.includes('</amp-img>')) {
|
|
|
+ rblocks.push({ 'type': 'img', 'text': crossLine });
|
|
|
foundImg = false;
|
|
|
crossLine = "";
|
|
|
}
|
|
@@ -105,19 +105,29 @@ function parseMd(content) {
|
|
|
if (line.includes('<amp-youtube') || foundYT) {
|
|
|
crossLine += line;
|
|
|
foundYT = true;
|
|
|
- if (line.includes('</amp-youtube>'))
|
|
|
- {
|
|
|
- blocks.push({ 'type': 'youtube', 'text': crossLine });
|
|
|
+ if (line.includes('</amp-youtube>')) {
|
|
|
+ rblocks.push({ 'type': 'youtube', 'text': crossLine });
|
|
|
foundYT = false;
|
|
|
crossLine = "";
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- blocks.push({ 'type': 'para', 'text': line });
|
|
|
+ if (line.includes('<table') || foundTBL) {
|
|
|
+ crossLine += line;
|
|
|
+ foundTBL = true;
|
|
|
+ if (line.includes('</table>')) {
|
|
|
+ rblocks.push({ 'type': 'table', 'text': crossLine });
|
|
|
+ foundTBL = false;
|
|
|
+ crossLine = "";
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ rblocks.push({ 'type': 'para', 'text': line });
|
|
|
}
|
|
|
-
|
|
|
- return blocks
|
|
|
+
|
|
|
+ return rblocks
|
|
|
}
|
|
|
|
|
|
const parseTitle = line => {
|
|
@@ -149,15 +159,39 @@ const parseAmpImg = line => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class MDParser
|
|
|
-{
|
|
|
+function tableTextToArray(tableHtml) {
|
|
|
+ tbl = document.createElement('table');
|
|
|
+ tbl.innerHTML = tableHtml.replace('<table>', '').replace('</table>', '');
|
|
|
+ var tableInfo = Array.prototype.map.call(tbl.querySelectorAll('tr'), function (tr) {
|
|
|
+ return Array.prototype.map.call(tr.querySelectorAll('td'), function (td) {
|
|
|
+ return td.innerHTML;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return tableInfo;
|
|
|
+}
|
|
|
+
|
|
|
+function tableArrayToHtml(tableArray) {
|
|
|
+ tbl = document.createElement('table');
|
|
|
+ for (j = 0; j < tableArray.length; j++) {
|
|
|
+ tr = document.createElement('tr');
|
|
|
+ for (k = 0; k < tableArray[j].length; k++) {
|
|
|
+ td = document.createElement('td');
|
|
|
+ td.innerHTML = tableArray[j][k];
|
|
|
+ tr.appendChild(td);
|
|
|
+ }
|
|
|
+ tbl.appendChild(tr);
|
|
|
+ }
|
|
|
+ //alert(tbl.outerHTML.toString());
|
|
|
+ return tbl.outerHTML.toString();
|
|
|
+}
|
|
|
+
|
|
|
+class MDParser {
|
|
|
|
|
|
- constructor(MDtext)
|
|
|
- {
|
|
|
+ constructor(MDtext) {
|
|
|
this.headerText = "";
|
|
|
this.contentText = "";
|
|
|
for (var line of MDtext.split('\n')) {
|
|
|
- console.log(line);
|
|
|
+ //console.log(line);
|
|
|
}
|
|
|
}
|
|
|
|