From 60cf2e0e165b8269fb4b2a1a2dafa969e4bd6f71 Mon Sep 17 00:00:00 2001 From: mikesamuel Date: Mon, 14 Jul 2008 22:58:26 +0000 Subject: [PATCH] Added support for 'nocode' spans to allow entire sections of markup to be placed outside the flow of source code tokens. google.code plans to use this for line numbers and code review comments. --- CHANGES.html | 14 +++-- README.html | 18 +++++++ src/prettify.js | 83 +++++++++++++++++++++++------ tests/prettify_test.html | 112 +++++++++++++++++++++++++++++++-------- 4 files changed, 188 insertions(+), 39 deletions(-) diff --git a/CHANGES.html b/CHANGES.html index 912a0944..4bbb7179 100644 --- a/CHANGES.html +++ b/CHANGES.html @@ -27,9 +27,9 @@

29 March 2007

(test)
  • Fixed entity handling so that the caveat
    -

    Caveats: please properly escape less-thans. x&lt;y - instead of x<y, and use " instead of - &quot; for string delimiters.

    +

    Caveats: please properly escape less-thans. x&lt;y + instead of x<y, and use " instead of + &quot; for string delimiters.

    is no longer applicable.
  • Added noisefree's C# @@ -49,5 +49,13 @@

    5 Jul 2008

    +

    14 Jul 2008

    + diff --git a/README.html b/README.html index 58864be8..9929ae53 100644 --- a/README.html +++ b/README.html @@ -118,6 +118,24 @@

    Why doesn't Prettyprinting of strings work on WordPress?

    >WordPress's help center for info on how to stop smart quoting of code snippets.

    +

    How do I put line numbers in my code?

    +

    You can use the nocode class to identify a span of markup + that is not code. +

    <pre class=prettyprint>
    +<span class="nocode">1:</span> /* This is line 1 of my code
    +<span class="nocode">2:</span>  * and here's line 2 */
    +<span class="nocode">3:</span> print("I'm line number 3");
    +</pre>
    +produces +
    +1: /* This is line 1 of my code
    +2:  * and here's line 2 */
    +3: print("I'm line number 3");
    +
    + +

    For a more complete example see the issue22 + testcase.

    +


    diff --git a/src/prettify.js b/src/prettify.js index cf0cb697..0c3840d9 100644 --- a/src/prettify.js +++ b/src/prettify.js @@ -63,7 +63,7 @@ var PR_TAB_WIDTH = 8; var PR_normalizedHtml; /** Contains functions for creating and registering new language handlers. - * @namespace + * @type {Object} */ var PR; @@ -80,11 +80,11 @@ var prettyPrintOne; */ var prettyPrint; -/** browser detection. */ -function pr_isIE6() { +/** browser detection. @extern */ +function _pr_isIE6() { var isIE6 = navigator && navigator.userAgent && /\bMSIE 6\./.test(navigator.userAgent); - pr_isIE6 = function () { return isIE6; }; + _pr_isIE6 = function () { return isIE6; }; return isIE6; } @@ -170,6 +170,12 @@ function pr_isIE6() { /** token style for an sgml attribute value. */ var PR_ATTRIB_VALUE = 'atv'; + /** + * A class that indicates a section of markup that is not code, e.g. to allow + * embedding of line numbers within code listings. + */ + var PR_NOCODE = 'nocode'; + function isWordChar(ch) { return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); } @@ -366,7 +372,7 @@ function pr_isIE6() { /** returns a function that expand tabs to spaces. This function can be fed * successive chunks of text, and will maintain its own internal state to * keep track of how tabs are expanded. - * @return {function (plainText : string) : string} a function that takes + * @return {function (string) : string} a function that takes * plain text and return the text with tabs expanded. * @private */ @@ -422,6 +428,7 @@ function pr_isIE6() { var pr_commentPrefix = /^