This post introduces some handy tricks for using special syntax in the Astro AntfuStyle Theme to enhance your Markdown/Mdx content. These shortcuts let the theme’s built-in integrations or plugins handle the heavy lifting, automatically converting everything into HTML --- no need to write complex code yourself! 🎨
Callouts (Alerts / Admonitions)#
Supported by rehype-callouts, you can modify the plugin’s configuration in plugins/index.ts
.
If you change the theme
configuration (default: 'vitepress'
), you will also need to update the imported CSS file in src/styles/markdown.css
(@import 'rehype-callouts/theme/yourconfig'
).
Highlights information that users should take into account, even when skimming.
title
!Optional information to help a user be more successful.
This is a collapsible callout, initially close.
Crucial information necessary for users to succeed.
This is a collapsible and nested callout, initially open.
Critical content demanding immediate user attention due to potential risks.
This is also a collapsible callout.
Negative potential consequences of an action.
Fully-featured Code Blocks#
Supported by astro-expressive-code with @expressive-code/plugin-collapsible-sections and @expressive-code/plugin-line-numbers plugins to add styling and extra functionality for code blocks.
To customize code block themes or functionality, modify the ec.config.mjs
file at the project root after reviewing the Configuring Expressive Code, such as change themes, enable word wrap, or toggle line numbers.
Here’s a quick preview of what’s possible. Check the detailed guide for more info.
Syntax Highlighting#
Code editor frames#
Terminal frames#
Marking full lines & line ranges#
Selecting line marker types (mark, ins, del)#
Adding labels to line markers#
Adding long labels on their own lines#
Using diff-like syntax#
Marking individual text inside lines (Plaintext search strings)#
Marking individual text inside lines (Regular expressions)#
Marking individual text inside lines (Selecting inline marker types (mark, ins, del))#
Configuring word wrap per block#
Configuring indentation of wrapped lines#
Collapsible sections#
Displaying line numbers per block#
Changing the starting line number#
Image Caption & Link#
Build on remark-directive with a custom remark-image-container
plugin (located in plugins/remark-image-container.ts
) to quickly add image captions,links and more.
You can refer to the Remark Directive Syntax for a quick overview of its basic rules --- it’s easy to understand and remember!
:::image-figure
#
The custom directive creates a block with an image, figcaption, and optional styling, much like a figure in academic papers.
:::image-figure[caption]{<figcaption> attrs}
: The square brackets hold the figcaption (if not set, the alt text from ![]()
will be used as the default), and curly braces are for inline styles or supported attributes.
![alt](image path)(<img> attrs)
: Standard Markdown image syntax with optional attributes inside parentheses (powered by remark-imgattr, allowing you to adjust the size of individual images).
:::image-a
#
The custom directive wraps an image inside a link, making it clickable.
:::image-a{<a> attrs}
: Define the link (href), styles, or classes in the curly braces for <a>
element.
![alt](image path)(<img> attrs)
: Same as above.
Video Embedding(::video
)#
Similarly, this theme includes predefined directives through a custom remark-sugar-directive
plugin (located in plugins/remark-sugar-directive.ts
), enabling quick implementation of features like video embedding, styled GitHub links, badge-like markers and details dropdown as described below.
The custom ::video
directive allows for consistent video embedding across different platforms, with flexible options for configuration.
::video{<youtubeId|bilibiliId|vimeoId> <noScale> <iframeSrc>}
: Curly braces contain the platform-specific video ID, along with optional parameters.
Styled GitHub Link(:link
)#
The custom :link
directive simplifies the process of creating styled links to GitHub repositories, users/organizations, or any external URLs with streamlined syntax.
Basic Syntax
Use :link
with display text in square brackets and id
parameter (or shorthand with a #
prefix) in curly braces.
Example 1: :link[Astro]{#withastro/astro}
or :link[Astro]{id=withastro/astro}
creates a link to Astro repo.
Example 2: :link[Stephanie Lin]{#@lin-stephanie}
links to the GitHub profile of the project maintainer, Stephanie Lin.
Example 3: :link[Vite]{id=@vitejs}
links to the GitHub profile of the Vite organization.
When linking to a GitHub user or organization, you must prepend the id
with @
.
If the []
part is omitted, the link will display the text of the id
parameter by default.
Specific Subsections
The :link
directive also supports linking to specific sections within a GitHub user or organization using the tab
parameter.
Example 4: :link{#@lin-stephanie tab=repositories}
links directly to the repositories tab of the GitHub user, like lin-stephanie. For GitHub users, valid tab
options: 'repositories','projects', 'packages', 'stars', 'sponsoring', 'sponsors'
.
Example 5: :link{#@vitejs tab=org-people}
links directly to the people section of a GitHub organization, like vitejs For GitHub organizations, valid tab
options: 'org-repositories', 'org-projects', 'org-packages', 'org-sponsoring', and 'org-people'
.
External URLs
When you want to link to something other than a GitHub resource, use the link
parameter to customize external links. This parameter is required if no id
is specified.
Example 6: :link[Google]{link=https://www.google.com/}
creates an external link to the Google.
Icon and Style Customization
You can customize icons with the imageUrl
parameter or adjust button styles using the style
parameter (optional values: 'square', 'rounded', 'github'
).
Example 7: :link[Astro]{#withastro/astro style=rounded}
creates a rounded button like Astro.
Example 8: :link[Vite]{id=@vitejs style=square}
creates a square button like Vite.
Example 9: :link{#lin-stephanie/astro-antfustyle-theme style=github}
creates a GitHub-styled link like:
lin-stephanie/astro-antfustyle-theme
Example 10: :link[send a little encouragement my way ❤️]{link=https://github.com/sponsors/lin-stephanie imageUrl=https://github.githubassets.com/assets/mona-e50f14d05e4b.png}
fully customizes a link.
Thanks for making it this far! Writing is no easy task --- maybe you’d like to send a little encouragement my way ❤️.
Badge-Like Markers(:badge
)#
The :badge
directive allows you to add customizable markers to improve document visuals.
There are built-in markers that automatically apply predefined labels and colors based on the configuration:
badge-a
: ARTICLEbadge-v
: VIDEObadge-o
: OFFICIALbadge-f
: FEEDbadge-t
: TOOLbadge-w
: WEBSITEbadge-g
: GITHUB
You can find and redefine these configurations in plugins/remark-sugar-directive.ts
.
Additionally, you can use :badge[Text]{<color>}
for easy visual customization of badges. For example: :badge[ISSUE]{color=#aaf233}
will display as ISSUE. If no color is specified, the default appearance will look like This.
Details Dropdown#
Details Dropdown
- List item 1
- List item 2
- List item 3
- List item 4
Additionally, it also supports usage similar to the examples in remark-directive.
Wrapping Up#
With the features above, the theme streamlines your Markdown/MDX content creation without requiring you to dive into complex HTML or CSS. Just focus on your ideas and let the theme handle the rest!
If you’re feeling adventurous, consider defining your own custom “directive syntax sugar” to tailor the experience even further! Contributions are always welcome --- feel free to join the discussion or submit an issue or pull request.
Thanks for checking out the theme. Have fun and enjoy creating! ⚡️