Le 17/03/2016 à 21:35, André Malo a écrit :
* André Malo wrote:

* Marion & Christophe JAILLET wrote:
Le 10/03/2016 06:28, jaillet...@apache.org a écrit :
Should prettyprint be tweaked to handle it? (I've seen that the version
we use is not the same as the latest available at
https://github.com/google/code-prettify)
I quick test with the latest version, without backporting modification
applied to the original prettify.js file, looks promising.
So IMHO, it is either a bug now fixed in prettify.js itself or an issue
introduced when it has been adapted for our own use.

I leave my change in trunk
http://httpd.apache.org/docs/trunk/en/howto/access.html) but revert it
for now in 2.4.x.
I'll give it a closer look later.
too close... ouch.

apparently there's no documentation how the prettify.js file was generated.
Need to figure that out before I can replace it. If someone has more
experience here, please speak up :-) Otherwise I'll dig through there build
system as soon as I get around to it :/

(also, loading from an external server as it's "recommended" by google is
not an option)

Cheers,

What about the attached patch?

The main idea is that we should try to fix leading/ending newlines/spaces *only* at the beginning and at the end of a node to pretiffy.

Actually, we perform the clean-up for *each underlying node*, if any.
In the example below, the use of <var> within the block generates some child nodes. This why the strings get concatenated.
Without these <var>, the output looks correct.


The attached patch:
- removes the leading NL/spaces for the *first* node only (see the new init var) - improve the existing "replace(/\n$/..." and turn it into "replace(/\s+$/..." to handle all ending NL/spaces


On HTML code such as:
--------------
    <pre class="prettyprint lang-config">





                 Require host <var>address</var>
sdfs


   Require ip <var>ip.address</var>
ssfsf


    </pre>
--------------
the output is as expected

That is to say:
   - leading NL removed
   - leading spaces removed
   - NL within the block kept
   - leading spaces within the block kept
   - ending NL removed
   - ending spaces removed



Note that doc that already add an arbitrary <br /> to keep the erroneously removed NL, should now be fixed. Otherwise a new NL will be generated (the NL in the <pre> block + the <br />) I don't remember where, but I've already seen such a construction in the doc.

CJ
Index: style/scripts/prettify.js
===================================================================
--- style/scripts/prettify.js   (révision 1740877)
+++ style/scripts/prettify.js   (copie de travail)
@@ -533,6 +533,7 @@
     var length = 0;
     var spans = [];
     var k = 0;
+    var init = 1;
   
     function walk(node) {
       switch (node.nodeType) {
@@ -554,10 +555,11 @@
             if (!isPreformatted) {
               text = text.replace(/[ \t\r\n]+/g, ' ');
             } else {
+              if (init == 1) {
+                text=text.replace(/^\s+/,'');  // Remove leading newlines and 
spaces
+                init = 0;                      // (but only for the first node)
+              }
               text = text.replace(/\r\n?/g, '\n');  // Normalize newlines.
-              text = text.replace(/^(\r?\n\s*)+/g, '');  // Remove leading 
newlines
-              text = text.replace(/^\s*/g, '');  // Remove leading spaces due 
to indented formatting
-              text = text.replace(/(\r?\n\s*)+$/g, '');  // Remove ending 
newlines
               
             }
             // TODO: handle tabs here?
@@ -572,8 +574,9 @@
   
     walk(node);
   
+    // Remove ending newlines and spaces
     return {
-      sourceCode: chunks.join('').replace(/\n$/, ''),
+      sourceCode: chunks.join('').replace(/\s+$/, ''),
       spans: spans
     };
   }

---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscr...@httpd.apache.org
For additional commands, e-mail: docs-h...@httpd.apache.org

Reply via email to