Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make code blocks look more like Stata code #20

Open
2 tasks
arthur-shaw opened this issue Feb 5, 2024 · 7 comments
Open
2 tasks

Make code blocks look more like Stata code #20

arthur-shaw opened this issue Feb 5, 2024 · 7 comments
Labels
looks 👀 👍 Looks/styling of the site
Milestone

Comments

@arthur-shaw
Copy link
Collaborator

arthur-shaw commented Feb 5, 2024

To my mind, this entails:

  • Syntax highlighting
  • Styling that makes code block look like Stata console/dofile editor

This might translate into a few tasks

  • Mark code blocks as Stata--ideally when writing from md to qmd. See Quarto docs here.
  • Apply a Stata-looking style. Either adopting a built-in style that's close or rolling our own. See Quarto docs here
@arthur-shaw
Copy link
Collaborator Author

arthur-shaw commented Feb 5, 2024

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
Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator

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

@arthur-shaw
Copy link
Collaborator Author

arthur-shaw commented Feb 15, 2024

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
Copy link
Collaborator Author

arthur-shaw commented Feb 22, 2024

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
```

  1. Build HTML file with Pandoc
pandoc stata_test.md -f markdown -t html -s -o stata_test.html

Result:

image

@arthur-shaw
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
looks 👀 👍 Looks/styling of the site
Projects
None yet
Development

No branches or pull requests

2 participants