mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 05:34:58 +00:00
LibMarkdown: Render slugified anchor tag in heading
Because slugify function accepts AK::String, which can hold unicode code_points as well, heading text is normalised to ensure with NFD form to ensure same binary respresentation of a particular string.
This commit is contained in:
parent
f1b79e0cd3
commit
da8a3f9ff2
2 changed files with 6 additions and 2 deletions
|
@ -15,4 +15,4 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_lib(LibMarkdown markdown)
|
||||
target_link_libraries(LibMarkdown PRIVATE LibJS LibRegex LibSyntax)
|
||||
target_link_libraries(LibMarkdown PRIVATE LibUnicode LibJS LibRegex LibSyntax)
|
||||
|
|
|
@ -4,15 +4,19 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Slugify.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibMarkdown/Heading.h>
|
||||
#include <LibMarkdown/Visitor.h>
|
||||
#include <LibUnicode/Normalize.h>
|
||||
|
||||
namespace Markdown {
|
||||
|
||||
DeprecatedString Heading::render_to_html(bool) const
|
||||
{
|
||||
return DeprecatedString::formatted("<h{}>{}</h{}>\n", m_level, m_text.render_to_html(), m_level);
|
||||
auto input = Unicode::normalize(m_text.render_for_raw_print().view(), Unicode::NormalizationForm::NFD);
|
||||
auto slugified = MUST(AK::slugify(input));
|
||||
return DeprecatedString::formatted("<h{} id='{}'><a href='#{}'>#</a> {}</h{}>\n", m_level, slugified, slugified, m_text.render_to_html(), m_level);
|
||||
}
|
||||
|
||||
Vector<DeprecatedString> Heading::render_lines_for_terminal(size_t) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue