From 1760b262c2d99d7803184e471116478ef18ff4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Laleve=CC=81e?= Date: Thu, 25 May 2017 14:55:24 +0200 Subject: [PATCH] - update asciidoctor - improve transforming xooki source into asciidoc source --- build-release.xml | 36 ++++++-------- doc/xooki2asciidoc/xooki2asciidoc.js | 70 ++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 31 deletions(-) diff --git a/build-release.xml b/build-release.xml index 7e3fc23d..65c13c59 100644 --- a/build-release.xml +++ b/build-release.xml @@ -63,8 +63,8 @@ - - + + @@ -164,35 +164,27 @@ - - - - - - - - - - - - - - - - + - + - - + + + + - + diff --git a/doc/xooki2asciidoc/xooki2asciidoc.js b/doc/xooki2asciidoc/xooki2asciidoc.js index d9ed69a2..27fb62f9 100644 --- a/doc/xooki2asciidoc/xooki2asciidoc.js +++ b/doc/xooki2asciidoc/xooki2asciidoc.js @@ -353,7 +353,8 @@ xooki.string = { // empty match are not allowed return null; } - + + print('matched!\n'); //print('matched !' + str.substring(openResult.begin, closeResult.end) + '\n'); var children = []; @@ -805,7 +806,7 @@ xooki.input = { from = 0; while (codeSection != null) { processedSection = "\n[source]\n----\n" - + input.substring(codeSection.innerStart, codeSection.innerEnd) + + input.substring(codeSection.innerStart, codeSection.innerEnd).replace(//g, "GREATER_THAN_IN_CODE") + "\n----\n\n"; input = input.substring(0, codeSection.outerStart) + processedSection @@ -895,6 +896,29 @@ xooki.input = { s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp(''), from); } + print('search postit\n') + s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp('')); + from = 0; + while (s != null) { + processedSection = "\n[NOTE]\n====\n" + input.substring(s.innerStart, s.innerEnd) + "\n====\n"; + input = input.substring(0, s.outerStart) + processedSection + input.substring(s.outerEnd); + from = s.outerStart + processedSection.length; + s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp(''), from); + } + + print('search shell\n') + s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp('')); + from = 0; + while (s != null) { + processedSection = "\n[source,shell]\n----\n" + + input.substring(s.innerStart, s.innerEnd).replace(/
/g, "").replace(/<\/pre>/g, "")
+                    + "\n----\n\n";
+                print("processedSection='" + processedSection + "'")
+                input = input.substring(0, s.outerStart) + processedSection + input.substring(s.outerEnd);
+                from = s.outerStart + processedSection.length;
+                s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp(''), from);
+            }
+
             print('search step\n')
             s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp(''));
             from = 0;
@@ -905,26 +929,27 @@ xooki.input = {
                 s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp(''), from);
             }
 
-            print('search shell\n')
-            s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp(''));
+            print('search ivy-file\n')
+            s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp(''));
             from = 0;
             while (s != null) {
                 processedSection = input.substring(s.innerStart, s.innerEnd);
                 input = input.substring(0, s.outerStart) + processedSection + input.substring(s.outerEnd);
                 from = s.outerStart + processedSection.length;
-                s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp(''), from);
+                s = xooki.string.findSection(input, new RegExp(']*>'), new RegExp(''), from);
             }
 
             print('search img\n')
-            s = xooki.string.find(input, new RegExp(''));
+            s = xooki.string.find(input, new RegExp(''));
             from = 0;
             while (s != null) {
-                processedSection = " image:" + s.matcher[1] + "[]"
+                imgSrc = s.matcher[1].replace(new RegExp('^.*src\\s*=\\s*\\"([^\\"]*)\\".*$'), "$1")
+                processedSection = "image::" + imgSrc + "[]"
                 input = input.substring(0, s.begin)
                     + processedSection
                     + input.substring(s.end);
                 from = s.begin + processedSection.length;
-                s = xooki.string.find(input, new RegExp(''), from);
+                s = xooki.string.find(input, new RegExp(''), from);
             }
 
             print('search img title\n')
@@ -1208,6 +1233,15 @@ xooki.input = {
                     if (!first) {
                         start = lastEnd;
                         betweenliContent = input.substring(lastEnd, sli.outerStart);
+                        iSpace = 0
+                        while (iSpace < betweenliContent.length && (betweenliContent.charAt(iSpace) == ' ' || betweenliContent.charAt(iSpace) == '\t')) {
+                            iSpace++;
+                        }
+                        if (betweenliContent.charAt(iSpace) == "\n") {
+                            betweenliContent = " +" + betweenliContent;
+                        } else {
+                            betweenliContent = " +\n" + betweenliContent;
+                        }
                     }
                     processedSection = betweenliContent + "\n" + innerindent + input.substring(sli.innerStart, sli.innerEnd).replace(/\\s/, ' ');
                     input = input.substring(0, start)
@@ -1223,7 +1257,19 @@ xooki.input = {
                     print(input.substring(from, from + 100));
                     return input;
                 }
-                input = input.substring(0, s.begin) + input.substring(s.end);
+
+                afterLastContent = input.substring(lastEnd, s.begin);
+                iSpace = 0
+                while (iSpace < afterLastContent.length && (afterLastContent.charAt(iSpace) == ' ' || afterLastContent.charAt(iSpace) == '\t')) {
+                    iSpace++;
+                }
+                if (afterLastContent.charAt(iSpace) == "\n") {
+                    afterLastContent = " +" + afterLastContent;
+                } else {
+                    afterLastContent = " +\n" + afterLastContent;
+                }
+
+                input = input.substring(0, lastEnd) + afterLastContent + input.substring(s.end);
                 from = s.begin;
                 return htmllisttag(input, from, indent);
             }
@@ -1312,6 +1358,12 @@ xooki.input = {
                 print("found=" + (s != null) + "\n")
             }
 
+            input = input.replace(/LOWER_THAN_IN_CODE/g, "<").replace(/GREATER_THAN_IN_CODE/g, ">")
+
+            input = input.replace(/include::..\/..\/tutorial/g, "include::asciidoc/tutorial")
+            input = input.replace(/include::..\/tutorial/g, "include::asciidoc/tutorial")
+            input = input.replace(/include::tutorial/g, "include::asciidoc/tutorial")
+
             return input;
 		},
     },