lsms-worldbank / adodownr

⏬ Create Quarto package documentation website for Stata packages
Other
6 stars 1 forks source link

Make code blocks look more like Stata code #20

Open arthur-shaw opened 8 months ago

arthur-shaw commented 8 months ago

To my mind, this entails:

This might translate into a few tasks

arthur-shaw commented 8 months ago

For Stata-looking style, here are some (subjectively) good looking themes for Stata:

Need a YAML header like this for each:

---
highlight-style: atom-one
---

ayu-dark:

image

nord:

image

atom-one, which is adaptive

image

arthur-shaw commented 8 months ago

Note: there's a universal problem of highlighting Stata keywords as code even if they're behind comments. Might need a custom theme for this.

kbjarkefur commented 8 months ago

I use the keyword ```stata in the beginning of a code block. That seems to work. I have however, not built in support for this in ad_sthlp for when converting .mdhlp files to .sthlp. It is quite an easy fix, as all it needs is to test that the only thing coming after ``` is stata and then just disregard it as there is no syntax highlighting in sthlp.

It currently already works on README.md and on vignettes and I am already using it on in repkit. See for example this file: https://dime-worldbank.github.io/repkit/articles/ado-management-with-repado.html. Scroll down for some better examples.

kbjarkefur commented 8 months ago

Let me know if you see some reason for why ```stata is not sufficient.

arthur-shaw commented 8 months ago

For adding the language to the codeblock, we could also do this on the adodownr side.

However we do it, it seems like Stata keywords that appear after comments are still highlighted. Here's an example from repkit (next to last code block on the page you linked) :

image

If that's OK, we only need to say that these are Stata codeblocks.

If not, we might need to tweak the syntax highlighting tooling--perhaps making upstream changes to the tooling Quarto uses (e.g., Quarto highlights Stata via' Pandoc (see here); we could write a custom highlighter via skylighting (see here).

arthur-shaw commented 8 months ago

This turns out to be a Pandoc issue. I can replicate the behavior above with only Pandoc.

I'll raise an issue with Quarto, Pandoc, and/or skylighting, the library Quarto and Pandoc use for syntax highlighting.

I suspect

Steps to reproduce

  1. Create a Markdown file named stata_test.md containing a Stata code block
---
title: Hello
---

Here's some Stata code:

```stata
* Set PLUS to adopath and list it first, then list BASE first.
* This means that BASE is first and PLUS is second.
adopath ++  "${root}/code/ado"
adopath ++  BASE

2. Build HTML file with Pandoc

pandoc stata_test.md -f markdown -t html -s -o stata_test.html



Result:

![image](https://github.com/lsms-worldbank/adodownr/assets/47256431/a63a4c64-76cd-4d2c-a994-d802029bdf28)
arthur-shaw commented 8 months ago

We can track things on this issue for skylighting, an upstream component of Pandoc/Quarto.