【问题标题】:Pygments adding whitespace to HTML inside prePygments 在 pre 中向 HTML 添加空格
【发布时间】:2014-03-06 00:49:25
【问题描述】:

我正在使用 Pygments 对用户创建的一些 HTML 进行语法处理。

这就是我所拥有的,注意左边的随机填充。

随机空间也是可选的

我正在使用 Ruby 来渲染代码块

= raw Pygments.highlight(block.content, lexer: 'html', :options => {:lineanchors => "line", :lineos => true})

这是样式...

pre {
    counter-reset: line-numbering;
    border: solid 1px #d9d9d9;
    border-radius: 0;
    padding: 0;
    line-height: 23px;
    margin-bottom: 30px;
    white-space: pre;
    word-break: inherit;
    word-wrap: inherit;
    width: inherit;
    overflow: scroll;
}

pre a::before {
    content: counter(line-numbering);
    counter-increment: line-numbering;
    padding-right: 1em; /* space after numbers */
    width: 25px;
    text-align: right;
    opacity: 0.7;
    display: inline-block;
    color: #aaa;
    background: #eee;
    margin-right: 16px;
    padding: 2px 10px;
    font-size: 13px;
    border-right: 1px solid #dedede;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

pre a:first-of-type::before {
    padding-top: 10px;
    @include box-shadow(rgba(255, 255, 255, 0.9) 0px 1px 1px inset);
}

pre a:last-of-type::before {
    padding-bottom: 10px;
}

pre a:only-of-type::before {
    padding: 10px;
}

这是在 Pygments 主题之上,我使用的是 Autumn,请参阅此处https://github.com/richleland/pygments-css

有点困惑是什么导致了这个神秘的空白,但如果有人可能知道或经历过这个问题,我们将不胜感激。

谢谢

【问题讨论】:

    标签: css ruby-on-rails ruby syntax-highlighting pygments


    【解决方案1】:

    我在使用 redcarpet 时遇到了同样的问题。问题起源于 Haml 并解决了在 initalizers 中添加这一行。

    Haml::Template.options[:ugly] = true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-26
      • 2012-11-22
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      • 2016-05-23
      相关资源
      最近更新 更多