惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
GbyAI
GbyAI
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
博客园 - 叶小钗
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
量子位
S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
S
Security Affairs
Cisco Talos Blog
Cisco Talos Blog
Jina AI
Jina AI
L
LINUX DO - 热门话题
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
H
Hacker News: Front Page
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tenable Blog
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
IT之家
IT之家
A
About on SuperTechFans
AWS News Blog
AWS News Blog
MyScale Blog
MyScale Blog
The Register - Security
The Register - Security
T
Threatpost
Last Week in AI
Last Week in AI
The Hacker News
The Hacker News
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
S
Security @ Cisco Blogs
Project Zero
Project Zero
N
News | PayPal Newsroom
MongoDB | Blog
MongoDB | Blog
爱范儿
爱范儿
K
Kaspersky official blog
雷峰网
雷峰网
W
WeLiveSecurity
博客园 - 聂微东
D
DataBreaches.Net
博客园 - 司徒正美
V2EX - 技术
V2EX - 技术

Oskar Wickström

Coding on Paper Catching Typos on My Website with Browser Testing The Bombadil Terminal Experiment There and Back Again: From Quickstrom to Bombadil Computer Says No: Error Reporting for LTL A Year with the Daylight Computer Finding Bugs in a Coding Agent with Lightweight DST Machine: Learning; Human: Unlearning; How I Built “The Monospace Web” A Flexible Minimalist Neovim for 2024 Statically Typed Functional Programming with Python 3.12 Specifying State Machines with Temporal Logic Clearing Weeds and Planting Trees Introducing Quickstrom: High-confidence browser testing The TodoMVC Showdown: Testing with WebCheck Time Travelling and Fixing Bugs with Property-Based Testing Property-Based Testing in a Screencast Editor, Case Study 3: Integration Testing Property-Based Testing in a Screencast Editor, Case Study 2: Video Scene Classification Property-Based Testing in a Screencast Editor, Case Study 1: Timeline Flattening Property-Based Testing in a Screencast Editor: Introduction Why I’m No Longer Taking Donations Writing a Screencast Video Editor in Haskell Declarative GTK+ Programming with Haskell Finite-State Machines, Part 2: Explicit Typed State Transitions Modeling with Haskell Data Types Motor: Finite-State Machines in Haskell Automating the Build of your Technical Presentation Tagless Final Encoding of a Test Language Hyper: Elegant Weapons for a More Civilized Page Taking a Step Back from Oden Paramount Color Scheme for Vim
Custom Formatting in HTML and LaTeX Code Listings using Pandoc
Oskar Wickström · 2016-07-10 · via Oskar Wickström

I have worked intensively on the Oden User Guide lately, primarily on improving content, but also on providing high-quality PDF and HTML output formats with detailed control over typesetting.

For some code listings and syntax examples I want the typesetting to convey the meaning of text in the listing – user input, command output, placeholders, etc. The User Guide build uses Pandoc to transform Markdown documents to PDF (through LaTeX) and to HTML. I could not find a good way to express the custom formatting in a way that worked with both LaTeX and HTML using standard Pandoc functionality.

Therefore, I created a filter to handle my input format. Using this filter, I can write code listings in separate files, using a small subset of HTML. Here’s an example of a shell command listing source file from the User Guide:

$ <strong>GOPATH=PWD/target/go:$GOPATH go build -o hello hello/main</strong>
$ <strong>./hello</strong>
Hello, world!

The strong tags in the listing are part of the HTML subset I use. To include listings in the Pandoc Markdown source I use regular code block syntax and add the custom include and formatted attributes:

```{include=src/listings/hello-world-go-build-and-run.html formatted=true}
```

The output, both in HTML and PDF, looks like this:

$ GOPATH=PWD/target/go:$GOPATH go build -o hello hello/main
$ ./hello
Hello, world!

For listings explaining the syntax of the Oden language I want placeholders to be typeset in italic text. Where the language supports a sequence of forms I want to express that using placeholder expressions with subscripts. The following listing source file explains the let binding syntax of Oden.

let <em>identifier<sub>1</sub></em> = <em>expression<sub>1</sub></em>
    <em>identifier<sub>2</sub></em> = <em>expression<sub>2</sub></em>
    ...
    <em>identifier<sub>n</sub></em> = <em>expression<sub>n</sub></em>
in <em>body-expression</em>

When included in the document, just like in the example before, the output looks like this:

let identifier1 = expression1
    identifier2 = expression2
    ...
    identifiern = expressionn
in body-expression

The filter is very simplistic in that it only supports em, strong, and sub elements, but it suits the needs of the Oden User Guide. I find extending Pandoc with filters very powerful, and I hope you find this technique and the blog post useful. If you are interested in the complete solution, including the Makefile compiling the filter and running Pandoc, please see doc/user-guide in the Oden repository.

Long live Pandoc!