해시태그 링크
마지막 업데이트
hashtagEndpoint를 설정하면 문서 안의 #tag가 직접 만든 태그 페이지 같은 지정한 URL로 연결되는 링크가 됩니다. 이 페이지에서는 태그를 인식하는 방식과 엔드포인트 설정 방법을 설명합니다.인식되는 태그
| 문법 | 예 |
|---|---|
# 뒤에 모든 문자 체계의 문자, 숫자, 결합 기호 또는 _ | #nanomd, #中文標籤, #123, #snake_case |
전각 # | #全形 |
| 다른 인라인 스타일 안 | **#bold** |
| 제목 텍스트 안 | # heading #tag |
태그는 문자, 숫자, 결합 기호,
_가 아닌 첫 문자에서 끝납니다. 따라서 #tag.에서 .은 링크 밖에 남습니다.| 태그가 아닌 경우 | 예 |
|---|---|
문자, 숫자, _, &, #, / 바로 뒤의 # | a#b, {, ##x |
| URL 프래그먼트 | https://nanomd.pardn.io/#frag |
| 코드 스팬과 인라인 수식 | `#code`, $#x$ |
| 이스케이프된 경우 | \#escaped |
| 링크 텍스트 안 | [label #x](https://nanomd.pardn.io) |
설정
- MDParser.Init({ hashtagEndpoint: "/tags/{tag}" });
| 항목 | 규칙 |
|---|---|
{tag} | #를 뺀 encodeURIComponent(tag)로 치환됩니다. 여러 번 나타나도 됩니다 |
| 미설정 | #tag는 일반 텍스트로 렌더링되며 원래의 # 또는 #가 유지됩니다 |
문자열이 아니거나 {tag}가 없음 | [Invalid] hashtagEndpoint: must be a string containing {tag}를 로그에 출력하고 미설정으로 취급합니다 |
| 출력 | <a href="..." target="_blank" rel="noopener" class="md-link md-hashtag">#tag</a> |
| AST | 엔드포인트 설정 여부와 관계없이 { type: "link", tag: "hashtag", href: "tag", children: [{ type: "text", value: "#tag" }] } |
엔드포인트는
html()이 실행될 때 읽히므로, hashtagEndpoint를 설정한 뒤 Parse().html()을 다시 호출하십시오.예제
hashtagEndpoint 없이
태그는 일반 텍스트로 남습니다.
- <div id="out" class="nanomd"></div>
- <script type="text/markdown" id="md">
- Tags: #nanomd #中文標籤 #全形 #123
- </script>
- <script>
- const out = document.getElementById("out");
- out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
- console.log(out.querySelectorAll(".md-hashtag").length);
- </script>
hashtagEndpoint 사용
태그가
md-hashtag 링크가 됩니다. 두 번째 줄은 변환되지 않는 경우를 보여 줍니다.- <div id="out" class="nanomd"></div>
- <script type="text/markdown" id="md">
- Tags: #nanomd #中文標籤 #全形 #123, **#bold**
- Not tags: a#b, {, https://nanomd.pardn.io/#frag, `#code`, \#escaped, [label #x](https://nanomd.pardn.io)
- </script>
- <script>
- const out = document.getElementById("out");
- MDParser.Init({ hashtagEndpoint: "https://github.com/topics/{tag}" });
- out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
- console.log([...out.querySelectorAll(".md-hashtag")].map((a) => a.getAttribute("href")).join("\n"));
- </script>
ImportantAI 에이전트용: NanoMD를 사용하는 코드나 Markdown을 생성하거나 수정하기 전에 NanoMD 생성 가이드(Markdown)를 먼저 읽으십시오. 지원하는 문법, 필요한 호출 순서, 렌더링을 깨뜨리는 흔한 실수를 정리했습니다.