有没有办法将“水平线”(即—)的输出格式化为.docx文件?

huangapple go评论62阅读模式
英文:

Is there a way to format the "horizontal rule" (i.e., ---) output Quarto to .docx?

问题

我一直在尝试确定是否可以在从Quarto .qmd格式输出到.docx时格式化“水平线”(如Quarto视觉编辑器所称),或者在Markdown中使用---。默认情况下是粗的淡灰色线条,如果可能的话,我想要细的黑色线条。

我尝试在参考文档上编辑输出的线条样式,但这并不起作用。

英文:

I've been trying to work out if it's possible to format the "horizontal rule" (as Quarto visual editor calls it) or --- in markdown, when outputting from Quarto .qmd to .docx. The default is thick pale grey line, and I'd like a thin black line if possible.

I've tried editing the outputted line within a style on the reference-doc, but that doesn't work.

答案1

得分: 1

你可以使用 CSS 样式来更改文档中使用 --- 时水平规则线的背景颜色。创建一个名为 styles.css 的单独的 CSS 文件。以下是一些可重现的代码:

hr {
    height: 3px;
    background-color: #0000000;
}

输出:

有没有办法将“水平线”(即—)的输出格式化为.docx文件?

英文:

You could use css style to change the background color of the horizontal rule line when using --- in your document. Create separate css file called styles.css. Here is some reproducible code:

---
title: "Untitled"
format: 
  html:
    css: styles.css
---

## Quarto

Here is the horizontale rule line in black

---

Output:

有没有办法将“水平线”(即—)的输出格式化为.docx文件?

styles.css file:

hr {
    height: 3px;
    background-color: #0000000;
}

答案2

得分: 0

以下是您要翻译的内容:

"对于任何感兴趣的人,我找到了一种在Quarto中编辑.docx输出水平线的方法。我基于此处的一些代码编写了一个快速的lua过滤器,并设置它在Quarto中工作。

lua过滤器的原始代码如下

-- 将默认的灰色水平线转换为细黑线(可在第10行自定义)
-- h/t https://github.com/jgm/pandoc/issues/2573
-- h/t https://gist.github.com/Merovex/05e3216f8f4f6e965cd9d564b1496719
local horizontallinerule = [[<w:p>
  <w:pPr>
    <w:pStyle w:val="HorizontalRule"/>
      <w:ind w:firstLine="0"/>
      <w:jc w:val="center"/>
    <w:pBdr>
      <w:bottom w:val="single" w:color="000000"/>
    </w:pBdr>
  </w:pPr>
  <w:r>
    <w:t></w:t>
  </w:r>
</w:p>]]
function HorizontalRule (elem)
    if FORMAT == 'docx' then
      return pandoc.RawBlock('openxml', horizontallinerule)
    end
end

我还将其设置为在Quarto文档的_extensions文件中工作 这里"

英文:

For anyone interested, I figured out a way to edit the .docx output horizontal rule in Quarto. I wrote a quick lua filter based on the some of the code here and set it up to work in Quarto.

The raw code of the lua filter is here

-- Converts default grey horiztonal rule to thin black line (customizable in line 10)
-- h/t https://github.com/jgm/pandoc/issues/2573
-- h/t https://gist.github.com/Merovex/05e3216f8f4f6e965cd9d564b1496719
local horizontallinerule = [[<w:p>
  <w:pPr>
    <w:pStyle w:val="HorizontalRule"/>
      <w:ind w:firstLine="0"/>
      <w:jc w:val="center"/>
    <w:pBdr>
      <w:bottom w:val="single" w:color="000000"/>
    </w:pBdr>
  </w:pPr>
  <w:r>
    <w:t></w:t>
  </w:r>
</w:p>]]
function HorizontalRule (elem)
    if FORMAT == 'docx' then
      return pandoc.RawBlock('openxml', horizontallinerule)
    end
end

I also set it up to work in the _extensions file in a Quarto doc here

huangapple
  • 本文由 发表于 2023年6月13日 07:27:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76460850.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定