Skip to content

📑 Add literalinclude directive#610

Merged
rowanc1 merged 4 commits into
mainfrom
feat/include
Sep 19, 2023
Merged

📑 Add literalinclude directive#610
rowanc1 merged 4 commits into
mainfrom
feat/include

Conversation

@rowanc1
Copy link
Copy Markdown
Member

@rowanc1 rowanc1 commented Sep 19, 2023

This supports a new directive, literalinclude as well as all of the additional options across RST and Sphinx.

RST documentation:

Sphinx documentation:

See jupyter-book/jupyterlab-myst#189 and https://github.com/orgs/executablebooks/discussions/1026

There are a few more tweaks that will be necessary to bring this to jupyterlab-myst to expose the transform and extend to not having to read from disk, etc.

cc @nthiery @matthewfeickert @fperez who were asking for this over the last few months.

Comment on lines +30 to +31
const showLineNumbers =
options?.linenos || options?.['lineno-start'] || options?.['lineno-match'] || numberLines
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a portion of the bug in:

Line number is now turned on if lineno-start is included.

@rowanc1 rowanc1 requested a review from fwkoch September 19, 2023 19:37
Copy link
Copy Markdown
Member

@fwkoch fwkoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great - I didn't dig through all the logic around line numbers, etc, in detail, but testing and documentation both look thorough 👍

Despite all the logic complexity added, there was nice simplification around previously duplicated options/directives. My only comments are non-critical.

Comment thread docs/code.md Outdated
Comment thread docs/code.md Outdated
Comment thread packages/myst-cli/src/transforms/include.ts Outdated
Comment thread packages/myst-cli/src/transforms/include.ts
Comment thread packages/myst-directives/src/code.ts Outdated
Comment thread packages/myst-directives/src/code.ts
@rowanc1 rowanc1 merged commit 392ba77 into main Sep 19, 2023
@rowanc1 rowanc1 deleted the feat/include branch September 19, 2023 20:16
@nthiery
Copy link
Copy Markdown
Contributor

nthiery commented Sep 19, 2023

I confirm that the dev version of myst supports smoothly the literalincludes
in my documents.

Since I could not yet test it with JupyterLab, I actually started mystmd for the
first time on a real project of mine. Wow, this is sooo fast. True real time
rendering. This a game changer for authoring.

Guys, it's amazing what you are building!!!

Can't wait to switch over from Jupyter-book for my whole toolchain.

@rowanc1
Copy link
Copy Markdown
Member Author

rowanc1 commented Sep 19, 2023

⚡️💨🚀

Really glad you are up and running with the CLI -- we will get it over to Jupyter soon!

@fperez
Copy link
Copy Markdown
Contributor

fperez commented Sep 20, 2023

Pinging also @minrk who may have content using these.

Haven't had a chance to test it yet, but wanted to thank @rowanc1 & team for listening to our input! This is looking wonderful, will provide concrete feedback as soon as I have any. Hugely apreciated!

@nthiery
Copy link
Copy Markdown
Contributor

nthiery commented Sep 22, 2023

Dear @rowanc1,

There seems to be a little glitch in the tex export when literal-including indented code.
Here is an example:

I have a file mystere-correction.cpp containing:

void mystereTest() {
    /// BEGIN mystereTests
    CHECK( mystere(0) == ""             );
    CHECK( mystere(1) == "*\n"          );
    CHECK( mystere(2) == "*\n**\n"      );
    CHECK( mystere(3) == "*\n**\n***\n" );
    /// END mystereTests
}

It's included as such:

:::{literalinclude} mystere-correction.cpp
:start-after: BEGIN mystereTests
:end-before: END mystereTests
:::

The generated TeX looks as such; mind the indentation of the first line:

\begin{verbatim}
CHECK( mystere(0) == ""             );
    CHECK( mystere(1) == "*\n"          );
    CHECK( mystere(2) == "*\n**\n"      );
    CHECK( mystere(3) == "*\n**\n***\n" );
\end{verbatim}

Let me know if more detailed instructions to reproduce would be helpful.

The generated html is fine.

@fwkoch
Copy link
Copy Markdown
Member

fwkoch commented Sep 22, 2023

@nthiery - I pulled your above comment to a separate issue so it wasn't lost: #614

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.

4 participants