-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wang.jianbo
committed
Oct 15, 2024
1 parent
ba57b4e
commit b84c110
Showing
2 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% macro render(section) %} | ||
{% set first_bracket = "[[" %} | ||
{% set last_bracket = "]]" %} | ||
|
||
{% set wikiregex = "\\[\\[([^/]+?)\\]\\]" %} | ||
|
||
{% set_global processed_content = section.content %} | ||
|
||
{% for wikilink in section.content | split(pat=first_bracket) | slice(start=1) %} | ||
{% set link_parts = wikilink | split(pat=last_bracket) %} | ||
{% if link_parts | length >= 1 %} | ||
{% set link_content = link_parts | first %} | ||
{% set link_content = link_content | replace(from="?", to="\\?") %} | ||
{% set wikilink_pattern = first_bracket ~ link_content ~ last_bracket %} | ||
{% set url = get_url(path="@/books/" ~ link_content ~ ".md") %} | ||
{% set link = "<a href=" ~ url ~ ">" ~ link_content ~ "</a>" %} | ||
{% set_global processed_content=processed_content | replace(from=wikilink_pattern, to=link) %} | ||
{% endif %} | ||
{% endfor %} | ||
{{ processed_content | safe }} | ||
{% endmacro %} |