Skip to content

Conversation

jkrumbiegel
Copy link
Collaborator

@jkrumbiegel jkrumbiegel commented Sep 19, 2025

Currently, when you have a file A.qmd which has {{< include B.qmd >}} on line 101, and then some code in B.qmd errors on line 100, you get a stacktrace pointing to A.qmd on line 200 which is not helpful. So far, we've just been running quarto's pre-expanded markdown strings instead of the string from a qmd file to handle include shortcodes. But this didn't give us the ability to annotate with the correct line numbers.

This PR switches to manual handling of include shortcodes. As far as I can tell, this type of shortcode is the only one that modifies the markdown before handing it off to the execution engine so we should not be in danger of reimplementing too large a share of the quarto internals. (Cf. https://quarto.org/docs/authoring/shortcodes.html) In principle the logic is simple, once a line with an include shortcode is detected, the file at that location is parsed separately and all its chunks added into the overall list.

The quarto docs say the following (https://quarto.org/docs/authoring/includes.html):

Include shortcodes need to appear by themselves in a line, and they need to be surrounded by empty lines. This means that you cannot use an include shortcode inside markdown syntax (such as an item in a bulleted list).

and

Note that you can’t use the include shortcode within a computational code block itself - as the example above shows, the executable code block needs to be inside the included document.

so I think the way I detect the shortcode should cover all cases that are meant to work (what wouldn't work is to continue some markdown block with an included qmd, but I think that's excluded by the note above).

What I haven't implemented, yet, is the ignoring of shortcodes in code blocks that have {shortcodes=false} but this seems rather niche because you'd only need that for explaining the include shortcode in a document. https://quarto.org/docs/extensions/shortcodes.html#escaping

This fixes #310

Copy link

codecov bot commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 53.73134% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.58%. Comparing base (fa10ed9) to head (75d5c41).

Files with missing lines Patch % Lines
src/server.jl 53.73% 31 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #338      +/-   ##
==========================================
- Coverage   79.43%   78.58%   -0.85%     
==========================================
  Files          39       39              
  Lines        2071     2120      +49     
==========================================
+ Hits         1645     1666      +21     
- Misses        426      454      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jkrumbiegel
Copy link
Collaborator Author

A quarto-side solution seems to make more sense as they already have source-tracking machinery which we don't want to (incorrectly) replicate here. Cf. quarto-dev/quarto-cli#13401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source locations are misleading with include shortcodes

1 participant