-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace escaping based on passthroughs without universal escaping based on character substitutions: https://docs.asciidoctor.org/asciidoc/latest/subs/replacements/ fix #763
- Loading branch information
1 parent
be64902
commit e2ae861
Showing
110 changed files
with
3,751 additions
and
2,655 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
share/mrdocs/addons/generator/adoc/partials/markup/code-block.adoc.hbs
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{{#if id}}[#{{{id}}}] | ||
{{/if}} | ||
={{select level (repeat "=" level) (select @root.config.multipage "==" "=")}} {{> @partial-block }} | ||
={{{select level (repeat "=" level) (select @root.config.multipage "==" "=")}}} {{> @partial-block }} |
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
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,93 @@ | ||
// | ||
// This is a derivative work. originally part of the LLVM Project. | ||
// Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// Copyright (c) 2023 Vinnie Falco ([email protected]) | ||
// | ||
// Official repository: https://github.com/cppalliance/mrdocs | ||
// | ||
|
||
#include "AdocEscape.hpp" | ||
#include <mrdocs/Support/Handlebars.hpp> | ||
|
||
namespace clang::mrdocs::adoc { | ||
|
||
namespace { | ||
|
||
constexpr | ||
std::optional<std::string_view> | ||
HTMLNamedEntity(char const c) | ||
{ | ||
// If c has a named entity, we use it | ||
// Otherwise, we return std::nullopt | ||
switch (c) | ||
{ | ||
case '~': return "˜"; | ||
case '^': return "ˆ"; | ||
case '_': return "_"; | ||
case '*': return "*"; | ||
case '`': return "`"; | ||
case '#': return "#"; | ||
case '[': return "["; | ||
case ']': return "]"; | ||
case '{': return "{"; | ||
case '}': return "}"; | ||
case '<': return "<"; | ||
case '>': return ">"; | ||
case '\\': return "\"; | ||
case '|': return "|"; | ||
case '-': return "‐"; | ||
case '=': return "="; | ||
case '&': return "&"; | ||
case ';': return ";"; | ||
case '+': return "+"; | ||
case ':': return ":"; | ||
case '.': return "."; | ||
case '"': return """; | ||
case '\'': return "'"; | ||
case '/': return "/"; | ||
default: | ||
break; | ||
} | ||
return {}; | ||
} | ||
|
||
} // (anon) | ||
|
||
void | ||
AdocEscape(OutputRef& os, std::string_view str) | ||
{ | ||
static constexpr char reserved[] = R"(~^_*`#[]{}<>\|-=&;+:."\'/)"; | ||
for (char c: str) | ||
{ | ||
if (std::ranges::find(reserved, c) != std::end(reserved)) | ||
{ | ||
// https://docs.asciidoctor.org/asciidoc/latest/subs/replacements/ | ||
if (auto e = HTMLNamedEntity(c)) | ||
{ | ||
os << *e; | ||
} | ||
else | ||
{ | ||
os << "&#" << static_cast<int>(c) << ';'; | ||
} | ||
} | ||
else | ||
{ | ||
os << c; | ||
} | ||
} | ||
} | ||
|
||
std::string | ||
AdocEscape(std::string_view str) { | ||
std::string res; | ||
OutputRef os(res); | ||
AdocEscape(os, str); | ||
return res; | ||
} | ||
|
||
|
||
} // clang::mrdocs::adoc |
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,34 @@ | ||
// | ||
// This is a derivative work. originally part of the LLVM Project. | ||
// Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// Copyright (c) 2023 Vinnie Falco ([email protected]) | ||
// Copyright (c) 2024 Alan de Freitas ([email protected]) | ||
// | ||
// Official repository: https://github.com/cppalliance/mrdocs | ||
// | ||
|
||
#ifndef MRDOCS_LIB_GEN_ADOC_ADOCESCAPE_HPP | ||
#define MRDOCS_LIB_GEN_ADOC_ADOCESCAPE_HPP | ||
|
||
#include <mrdocs/Support/Handlebars.hpp> | ||
#include <string> | ||
#include <string_view> | ||
|
||
namespace clang::mrdocs::adoc { | ||
|
||
/** Escape a string for use in AsciiDoc | ||
*/ | ||
MRDOCS_DECL | ||
void | ||
AdocEscape(OutputRef& os, std::string_view str); | ||
|
||
MRDOCS_DECL | ||
std::string | ||
AdocEscape(std::string_view str); | ||
|
||
} // clang::mrdocs::adoc | ||
|
||
#endif |
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
Oops, something went wrong.