Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. diff --git a/Libraries/LibMarkdown/MDText.cpp b/Libraries/LibMarkdown/MDText.cpp
  2. index 9be080df..06018411 100644
  3. --- a/Libraries/LibMarkdown/MDText.cpp
  4. +++ b/Libraries/LibMarkdown/MDText.cpp
  5. @@ -1,6 +1,20 @@
  6. #include <AK/StringBuilder.h>
  7. #include <LibMarkdown/MDText.h>
  8.  
  9. +static String unescape(const StringView& text)
  10. +{
  11. + StringBuilder builder;
  12. + for (int i = 0; i < text.length(); ++i) {
  13. + if (text[i] == '\\' && i != text.length() - 1) {
  14. + builder.append(text[i + 1]);
  15. + i++;
  16. + continue;
  17. + }
  18. + builder.append(text[i]);
  19. + }
  20. + return builder.build();
  21. +}
  22. +
  23. String MDText::render_to_html() const
  24. {
  25. StringBuilder builder;
  26. @@ -97,6 +111,12 @@ bool MDText::parse(const StringView& str)
  27. for (int offset = 0; offset < str.length(); offset++) {
  28. char ch = str[offset];
  29.  
  30. + bool is_escape = ch == '\\';
  31. + if (is_escape && offset != str.length() - 1) {
  32. + offset++;
  33. + continue;
  34. + }
  35. +
  36. bool is_special_character = false;
  37. is_special_character |= ch == '`';
  38. if (!current_style.code)
  39. @@ -128,7 +148,7 @@ bool MDText::parse(const StringView& str)
  40.  
  41. if (current_span_start < str.length()) {
  42. Span span {
  43. - str.substring_view(current_span_start, str.length() - current_span_start),
  44. + unescape(str.substring_view(current_span_start, str.length() - current_span_start)),
  45. current_style
  46. };
  47. m_spans.append(move(span));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement