質問

Visual Basicコードしない、もしくは正しく描画する prettify.js ます。

にスタックオーバーフロー:

Partial Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'set page title
        Page.Title = "Something"
    End Sub

End Class

Visual Studio...

Visual Basic in Visual Studio

この README ドキュメント:

どうかを指定すること語っ コードです。

な言語を指定 以来、prettyprint()のようですね。す 指定の言語を指定する 言語の拡張とともに prettyprintクラスはこのように:

<pre class="prettyprint lang-html">
  The lang-* class specifies the language file extensions.
  Supported file extensions include
    "c", "cc", "cpp", "cs", "cyc", "java", "bsh", "csh", "sh",
    "cv", "py", "perl", "pl", "pm", "rb", "js",
    "html", "html", "xhtml", "xml", "xsl".
</pre>

思い当たらない lang-vb または lang-基礎 オプションです。なんだろうけど、日本人に存在する場として追加す。


注意:この VB.NET コードブロック 提案のためのスタックオーバーフロー.

役に立ちましたか?

解決

/編集:私は書き換えのします。

以下は写真にトイの問題です。そんな、より良い ください して使用します。VB構文強調べました。

私も追加したコード例では一部の複雑なコードをリテラルが返されます。しかし、誰も知らないうXLinqます。も仕事あります。の キーワード一覧 からにMSDN.文脈のキーワードは含まれません。たとえば、 GetXmlNamespace オペレーター?

このアルゴリズムを知ってリテラルタイプ文字です。るものでなければならないのか扱うことができる識別子型の文字げたいと思いましたが試されます。なお、コードの作 HTML.結果として、&, < >のに必要なこととして名(!) 主体は、単一の文字です。

しまいまして申し訳ありません長regex.

var highlightVB = function(code) {
    var regex = /("(?:""|[^"])+"c?)|('.*$)|#.+?#|(&amp;[HO])?\d+(\.\d*)?(e[+-]?\d+)?U?([SILDFR%@!#]|&amp;)?|\.\d+[FR!#]?|\s+|\w+|&amp;|&lt;|&gt;|([-+*/\\^$@!#%&<>()\[\]{}.,:=]+)/gi;

    var lines = code.split("\n");
    for (var i = 0; i < lines.length; i++) {
        var line = lines[i];

        var tokens;
        var result = "";

        while (tokens = regex.exec(line)) {
            var tok = getToken(tokens);
            switch (tok.charAt(0)) {
                case '"':
                    if (tok.charAt(tok.length - 1) == "c")
                        result += span("char", tok);
                    else
                        result += span("string", tok);
                    break;
                case "'":
                    result += span("comment", tok);
                    break;
                case '#':
                    result += span("date", tok);
                    break;
                default:
                    var c1 = tok.charAt(0);

                    if (isDigit(c1) ||
                        tok.length > 1 && c1 == '.' && isDigit(tok.charAt(1)) ||
                        tok.length > 5 && (tok.indexOf("&amp;") == 0 &&
                        tok.charAt(5) == 'H' || tok.charAt(5) == 'O')
                    )
                        result += span("number", tok);
                    else if (isKeyword(tok))
                        result += span("keyword", tok);
                    else
                        result += tok;
                    break;
            }
        }

        lines[i] = result;
    }

    return lines.join("\n");
}

var keywords = [
    "addhandler", "addressof", "alias", "and", "andalso", "as", "boolean", "byref",
    "byte", "byval", "call", "case", "catch", "cbool", "cbyte", "cchar", "cdate",
    "cdec", "cdbl", "char", "cint", "class", "clng", "cobj", "const", "continue",
    "csbyte", "cshort", "csng", "cstr", "ctype", "cuint", "culng", "cushort", "date",
    "decimal", "declare", "default", "delegate", "dim", "directcast", "do", "double",
    "each", "else", "elseif", "end", "endif", "enum", "erase", "error", "event",
    "exit", "false", "finally", "for", "friend", "function", "get", "gettype",
    "getxmlnamespace", "global", "gosub", "goto", "handles", "if", "if",
    "implements", "imports", "in", "inherits", "integer", "interface", "is", "isnot",
    "let", "lib", "like", "long", "loop", "me", "mod", "module", "mustinherit",
    "mustoverride", "mybase", "myclass", "namespace", "narrowing", "new", "next",
    "not", "nothing", "notinheritable", "notoverridable", "object", "of", "on",
    "operator", "option", "optional", "or", "orelse", "overloads", "overridable",
    "overrides", "paramarray", "partial", "private", "property", "protected",
    "public", "raiseevent", "readonly", "redim", "rem", "removehandler", "resume",
    "return", "sbyte", "select", "set", "shadows", "shared", "short", "single",
    "static", "step", "stop", "string", "structure", "sub", "synclock", "then",
    "throw", "to", "true", "try", "trycast", "typeof", "variant", "wend", "uinteger",
    "ulong", "ushort", "using", "when", "while", "widening", "with", "withevents",
    "writeonly", "xor", "#const", "#else", "#elseif", "#end", "#if"
]

var isKeyword = function(token) {
    return keywords.indexOf(token.toLowerCase()) != -1;
}

var isDigit = function(c) {
    return c >= '0' && c <= '9';
}

var getToken = function(tokens) {
    for (var i = 0; i < tokens.length; i++)
        if (tokens[i] != undefined)
            return tokens[i];
    return null;
}

var span = function(class, text) {
    return "<span class=\"" + class + "\">" + text + "</span>";
}

コード試験

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    'set page title
    Page.Title = "Something"
    Dim r As String = "Say ""Hello"""
    Dim i As Integer = 1234
    Dim d As Double = 1.23
    Dim s As Single = .123F
    Dim l As Long = 123L
    Dim ul As ULong = 123UL
    Dim c As Char = "x"c
    Dim h As Integer = &amp;H0
    Dim t As Date = #5/31/1993 1:15:30 PM#
    Dim f As Single = 1.32e-5F
End Sub

他のヒント

Prettifyな支援VBコメントとして、8月2009年.

車vb構文強調表示正常に動作して必要な三つのもの;

<script type="text/javascript" src="/External/css/prettify/prettify.js"></script>
<script type="text/javascript" src="/External/css/prettify/lang-vb.js"></script>

前のブロックの周りにコード例:

<PRE class="prettyprint lang-vb">
 Function SomeVB() as string
   ' do stuff
   i = i + 1
 End Function
</PRE>

Stackoverflowにlang-vb.js 包摂する機能を指定する言語を介値下げる: class="prettyprint lang-vb" ではなぜこの値は管理画面より変更可能です。

詳細については:見 のPrettify問題ログ

この間、追加コメント文字のコメントすることが見ても大丈夫です。例えば:

Sub TestMethod()
    'Method body goes here'
End Sub

また、脱内部のコメント文字は通常のvb-ファッション:

Sub TestMethod2()
    'Here''s another comment'
End Sub

Prettifyも扱う文字列リテラルとしてではなくコメントが、少なくともう大丈夫です。

もう一つの方法などの見が開始コメント追加 '//, このよう:

Sub TestMethod3()
    ''// one final comment
End Sub

その後も同様の取り扱いをさせていただき、コメントがおいてC-スタイルのコメントマーカー

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top