6
4

1 回答 1

3

为了重现该问题,您还可以添加其他内容吗?喜欢question.body的内容?

如果我在控制器上做这样的事情:

class HomeController < ApplicationController
  def index
    @data = <<EOF
~~~ cpp
#include <fstream.h>

int main (int argc, char *argv[]) {
return(0);
}
~~~
EOF
  end
end

和观点:

<pre class="lang-cpp prettyprint-override">
  <%= markdown @data %>
</pre>

它工作得很好,我可以毫无问题地看到解析的代码。question.body 的内容是什么?你能保存网页的内容(从你的浏览器)并将它保存在一个要点上以便我们调试吗?

谢谢


关于您的最后一条评论,它是一个简单的 CSS 问题,在您的样式表上,您可以添加:

.code {
  color: #DD1144 !important;
}

它会起作用,问题是你有一个写成这样的css规则:

pre .code {
  color: inherited;
}

那是使用从 body 类继承的颜色 #333333


这是一个关于更新 css 后的样子的屏幕:

在此处输入图像描述


带有您的代码的示例应用程序运行良好,我需要一个示例应用程序代码应用程序,或者一个示例代码,我们可以在其中重现您遇到的问题(没有用于格式化代码的正确 css/样式表)。

这是示例应用程序外观的示例:

在此处输入图像描述


在此处输入图像描述


最终编辑,问题不在于库,也不是您呈现问题的方式,而是您正在呈现的内容,检查问题的正文,这是我在实际呈现的正文中遇到的问题之一因为库应该呈现,但它没有像您期望的那样呈现:)

@data = <<EOF
    <p>I've been messing around with <a href="http://en.wikipedia.org/wiki/JSON">JSON</a> for some time, just pushing it out as text and it hasn't hurt anybody (that I know of), but I'd like to start doing things properly.</p>

    <p>I have seen <em>so</em> many purported "standards" for the JSON content type:</p>

    <pre><code>application/json
    application/x-javascript
    text/javascript
    text/x-javascript
    text/x-json
    </code></pre>

    <p>But which is correct, or best? I gather that there are security and browser support issues varying between them.</p>

    <p>I know there's a similar question, <em><a href="http://stackoverflow.com/questions/404470/what-mime-type-if-json-is-being-returned-by-a-rest-api">What MIME type if JSON is being returned by a REST API?</a></em>, but I'd like a slightly more targeted answer.</p>
EOF

这是我刚刚从 stackoverflow 复制/粘贴的另一个,它呈现的所有语法都突出显示,你注意到区别了吗?因此,更新您的爬虫以获取正确格式的问题,它将起作用

@data = <<EOF
Here is a piece of C++ code that shows some very peculiar performance. For some strange reason, sorting the data miraculously speeds up the code by almost 6x:

<!-- language: lang-cpp -->

    #include <algorithm>
    #include <ctime>
    #include <iostream>

    int main()
    {
        // Generate data
        const unsigned arraySize = 32768;
        int data[arraySize];

        for (unsigned c = 0; c < arraySize; ++c)
            data[c] = std::rand() % 256;

        // !!! With this, the next loop runs faster
        std::sort(data, data + arraySize);

        // Test
        clock_t start = clock();
        long long sum = 0;

        for (unsigned i = 0; i < 100000; ++i)
        {
            // Primary loop
            for (unsigned c = 0; c < arraySize; ++c)
            {
                if (data[c] >= 128)
                    sum += data[c];
            }
        }

        double elapsedTime = static_cast<double>(clock() - start) / CLOCKS_PER_SEC;

        std::cout << elapsedTime << std::endl;
        std::cout << "sum = " << sum << std::endl;
    }

 - Without `std::sort(data, data + arraySize);`, the code runs in **11.54** seconds.
 - With the sorted data, the code runs in **1.93** seconds.

----------

Initially I thought this might be just a language or compiler anomaly. So I tried it in Java:

<!-- language: lang-java -->

    import java.util.Arrays;
    import java.util.Random;

    public class Main
    {
        public static void main(String[] args)
        {
            // Generate data
            int arraySize = 32768;
            int data[] = new int[arraySize];

            Random rnd = new Random(0);
            for (int c = 0; c < arraySize; ++c)
                data[c] = rnd.nextInt() % 256;

            // !!! With this, the next loop runs faster
            Arrays.sort(data);

            // Test
            long start = System.nanoTime();
            long sum = 0;

            for (int i = 0; i < 100000; ++i)
            {
                // Primary loop
                for (int c = 0; c < arraySize; ++c)
                {
                    if (data[c] >= 128)
                        sum += data[c];
                }
            }

            System.out.println((System.nanoTime() - start) / 1000000000.0);
            System.out.println("sum = " + sum);
        }
    }

with a similar but less extreme result.

----------

My first thought was that sorting brings the data into cache, but my next thought was how silly that is because the array was just generated.

What is going on? Why is a sorted array faster than an unsorted array? The code is summing up some independent terms, the order should not matter.

EOF
于 2013-04-02T10:26:45.397 回答