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

code directive #7

Open
20 tasks
Tracked by #2
Mpdreamz opened this issue Nov 6, 2024 · 1 comment
Open
20 tasks
Tracked by #2

code directive #7

Mpdreamz opened this issue Nov 6, 2024 · 1 comment
Labels
authoring Relates to our markdown parser

Comments

@Mpdreamz
Copy link
Member

Mpdreamz commented Nov 6, 2024

Code

Kind Link
Reference https://mystmd.org/guide/directives#directive-code
Documentation https://mystmd.org/guide/code

A code-block environment with a language as the argument, and options for highlighting, showing line numbers, and an optional filename.

Implementation

  • Parses directives and aliases
  • Emits HTML
  • Unit tests
  • Validation (emits, warnings and errors).

Specification compliance:

  • Arguments is not parsed and treated as language option
  • Body is not parsed and treated as raw string
  • Options:
    • label, name (string) - Label the code to be cross-referenced or explicitly linked to.
    • enumerated, numbered (boolean) - Turn on/off the numbering for the specific code
    • enumerator, number (string) - Explicitly set the code number
    • class (string)
    • caption (parsed) - A parsed caption for the code block.
    • linenos (boolean)- Show line numbers
    • lineno-start (number) - Start line numbering from a particular value, default is 1. If present, line numbering is activated.
    • number-lines (number)
      Alternative for “lineno-start”, turns on line numbering and can be an integer that is the start of the line numbering.
    • emphasize-lines (string) - Emphasize particular lines (comma-separated numbers), e.g. “3,5”
    • filename (string)
      Show the filename in addition to the rendered code. The include directive will use the filename by default, to turn off this default set the filename to false.
  • Aliases:
    • code-block
    • sourcecode
This was referenced Nov 6, 2024
@Mpdreamz Mpdreamz added enhancement authoring Relates to our markdown parser labels Nov 6, 2024
@KOTungseth
Copy link

KOTungseth commented Nov 11, 2024

Context:

I'm also including my own notes ⬇️

Purpose

Present code clearly: Code blocks provide a visually distinct area for displaying code snippets, making it easier for users to read and understand programming syntax. This separation from regular text helps highlight important code sections.

Enhance readability: By formatting code with consistent indentation, spacing, and syntax highlighting, code blocks improve readability. This helps users quickly grasp the structure and flow of the code, which is especially important for complex code examples.

Facilitate copying: Code blocks are often designed to allow users to easily copy and paste code into their development environments. This convenience reduces errors caused by manual transcription and speeds up the implementation process.

Demonstrate functionality: Code blocks can illustrate specific functionality or usage examples, helping users understand how to implement a feature, use a library, or interact with an API. They provide practical context for the information being discussed.

Support multi-language examples: Documentation often needs to cover multiple programming languages. Code blocks allow for clear distinctions between different language examples, ensuring users know which code applies to their specific programming environment.

Enable syntax highlighting: Many documentation systems support syntax highlighting for code blocks, which enhances the visibility of keywords, comments, and other elements. This visual differentiation helps users quickly identify relevant parts of the code.

Encourage best practices: Code blocks can be used to showcase best practices, coding standards, or common pitfalls, guiding users in writing better, more efficient code. This is valuable for both novice and experienced developers.

Best practices

Use syntax highlighting: Leverage syntax highlighting to enhance the readability of code blocks. This visual distinction helps users quickly identify keywords, variables, and other elements, making it easier to understand the code.

Provide clear and descriptive context: Before or after the code block, include a brief explanation of what the code does, its purpose, and how it fits into the overall documentation. This context helps users understand why the code is relevant.

Keep code blocks short: Aim to keep code blocks concise and focused on a single concept or function. If a longer example is necessary, consider breaking it into smaller sections or providing a link to a more extensive resource.

Ensure code is executable: If possible, provide code that users can easily copy and paste into their development environments without modification. This reduces errors and enhances the user experience.

Include comments in code: Use comments within the code to explain critical parts or complex logic. This can help users understand the code's intent and facilitate learning.

Provide examples and use cases: Whenever applicable, follow code blocks with real-world examples or scenarios that demonstrate how the code can be used. This practical application helps users see the value of the code in context.

Test code for accuracy: Ensure that the code provided in the documentation is accurate, functional, and up-to-date. Regularly test code examples to verify they work as intended.

Indicate language: Clearly indicate the programming language used in each code block, especially when the documentation covers multiple languages. This helps users quickly identify the relevant syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
authoring Relates to our markdown parser
Projects
None yet
Development

No branches or pull requests

2 participants