Tin Tức

Blog 1

You are interested in Blog 1 right? So let's go together natuts.com look forward to seeing this article right here!

Note: Bài đăng này không có ý nghĩa ở đây. Vui lòng xem bài đăng gốc.

Một trong những bài viết trước đó của tôi cho biết rằng SyntaxHighlight chỉ hỗ trợ một ngôn ngữ trong thẻ pre mà không có bằng chứng. Trước khi nhúng danh sách mã nguồn để chứng minh điều này, tôi sẽ đưa ra nhiều quan điểm hơn và sau đó xác minh chúng.

highlight.js hỗ trợ nhưng google-code-prettify không. Ví dụ, bạn muốn đính kèm mã Matlab sau vào bài đăng của blog của bạn. SyntaxHighlight không hỗ trợ Matlab. Đối với highlight.js, đây là kết quả:

function [rr_array] = nest_fun(x,a)
%function to find sets of polynormials.
% a: set of constants, [A B C]
% x: variables in array
% Example: rr=nest_fun(2:10,[1 2 4;2 4 8])

n = size(a);
for i = 1:n
    A = a(i,1);
    B = a(i,2);
    C = a(i,3);
    rr_array{1,i}=['A=',num2str(A),', B=',... num2str(B),', C=',num2str(C)];
    rr_array{2,i}=polyx(x);

end

function r = polyx(xx)
    r = A.*x.^2 + B.*x +C;
end

end

Hình ảnh minh họa: Blog 1

highlight.js hoạt động trên một số máy tính.

Khi tôi viết bài đăng, highlight.js không hoạt động đúng, nhưng khi tôi từ bỏ việc thử và xem bài đăng này vào ngày hôm sau, mọi thứ đều ổn.

Bây giờ chúng ta hãy xem google-code-prettify hoạt động như thế nào.

function [rr_array] = nest_fun(x,a)
%function to find sets of polynormials.
% a: set of constants, [A B C]
% x: variables in array
% Example: rr=nest_fun(2:10,[1 2 4;2 4 8])

n = size(a);
for i = 1:n
    A = a(i,1);
    B = a(i,2);
    C = a(i,3);
    rr_array{1,i}=['A=',num2str(A),', B=',... num2str(B),', C=',num2str(C)];
    rr_array{2,i}=polyx(x);

end

function r = polyx(xx)
    r = A.*x.^2 + B.*x +C;
end

end

Mã được sao chép từ Ứng dụng của Matlab trong Kỹ thuật.

Lưu ý: Trong tệp README chính thức, được nói rằng chúng ta xác định lớp ngôn ngữ-* bằng phần mở rộng tập tin của nó (vd m), nhưng trên trang hiển thị mã nguồn của lang-matlab.js trên Google Code, nó trỏ đến kho chứa Github của tác giả, có một tệp README. Theo tệp đó, thẻ HTML phải là <pre class=”prettyprint lang-matlab”>, thay vì <pre class=”prettyprint lang-m”>.

Vì vậy, khi nhúng danh sách mã nguồn trên bằng cách sử dụng google-code-prettify, bạn sẽ viết như sau:

<pre class="prettyprint lang-matlab">function [rr_array] = nest_fun(x,a)
%function to find sets of polynormials.
% a: set of constants, [A B C]
% x: variables in array
% Example: rr=nest_fun(2:10,[1 2 4;2 4 8])

n = size(a);
for i = 1:n
    A = a(i,1);
    B = a(i,2);
    C = a(i,3);
    rr_array{1,i}=['A=',num2str(A),', B=',... num2str(B),', C=',num2str(C)];
    rr_array{2,i}=polyx(x);

end

function r = polyx(xx)
    r = A.*x.^2 + B.*x +C;
end

end</pre>

Bây giờ hãy quay lại chủ đề.

SyntaxHighlighter

Đoạn mã SyntaxHighlighter để nhúng Java:

<pre class="brush: java">
public class Hello {
    public static void main(String args[]) {
        System.out.println("Hello world!");
    }
}
</pre>

Vì ngôn ngữ được xác định bằng brush: html, không có tính năng đa ngôn ngữ trong SyntaxHighlighter.

highlight.js

<pre class="brush: java">
public class Hello {
    public static void main(String args[]) {
        System.out.println("Hello world!");
    }
}
</pre>

Vì vậy, highlight.js có thể hiển thị nhiều ngôn ngữ trong một container.

google-code-prettify

<pre class="brush: java">
public class Hello {
    public static void main(String args[]) {
        System.out.println("Hello world!");
    }
}
</pre>

Vì vậy, kết quả của google-code-prettify tương tự như của SyntaxHighlighter.

Kết quả tiếp theo của highlight.js

Chúng tôi kết thúc bài viết này với thêm kết quả trong highlight.js.

Để nhúng mã nguồn đa ngôn ngữ thành danh sách, highlight.js là điều bạn cần, nhưng nếu bạn cứ nhất quyết sử dụng google-code-prettify, đây là một số mã mẫu.

<pre class="prettyprint">
public class Hello {
    // Java code sample
    public static void main(String args[]) {
        System.out.println("Hello world!");
    }
}
<!-- CSS code -->
.sidebar #sidebar, .ss{
    margin-top: 12px !important;
    overflow-y: scroll !important;
}

# C++ code
#include <iostream>
using namespace std;

int main(void) {
    cout << "Hello world!" << endl;
    return 0;
}
</pre>

Conclusion: So above is the Blog 1 article. Hopefully with this article you can help you in life, always follow and read our good articles on the website: natuts.com

Related Articles

Back to top button