fix hex code length and use a exists hex to int method;
added docs for color codes
This commit is contained in:
parent
9ce34080f7
commit
6ca8dc18cf
@ -19,3 +19,34 @@ Styles can be combined. Example:
|
|||||||
Output:
|
Output:
|
||||||
|
|
||||||
***<ins>Message</ins>*** using *~~combed~~ combined* styles<ins>~~.~~</ins>
|
***<ins>Message</ins>*** using *~~combed~~ combined* styles<ins>~~.~~</ins>
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
|
||||||
|
Text color can be set using a color code: [#RRGGBB]
|
||||||
|
|
||||||
|
|
||||||
|
| Component | Purpose |
|
||||||
|
| --------- | --------------------------------- |
|
||||||
|
| R | Represents the intensity of red |
|
||||||
|
| G | Represents the intensity of green |
|
||||||
|
| B | Represents the intensity of blue |
|
||||||
|
|
||||||
|
### Example:
|
||||||
|
|
||||||
|
<span style="color: #ff0000">
|
||||||
|
<span style="color:rgb(105, 105, 105)">
|
||||||
|
[#ff0000]
|
||||||
|
</span>Red Text
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span style="color: #00ff00">
|
||||||
|
<span style="color:rgb(105, 105, 105)">
|
||||||
|
[#00ff00]
|
||||||
|
</span>Green Text
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span style="color: #0000ff">
|
||||||
|
<span style="color:rgb(105, 105, 105)">
|
||||||
|
[#0000ff]
|
||||||
|
</span>Blue Text
|
||||||
|
</span>
|
||||||
|
|||||||
@ -19,3 +19,33 @@
|
|||||||
Вывод:
|
Вывод:
|
||||||
|
|
||||||
***<ins>Сообщение</ins>***, демонстрирующее *~~обедненные~~ объединенные* стили<ins>~~.~~</ins>
|
***<ins>Сообщение</ins>***, демонстрирующее *~~обедненные~~ объединенные* стили<ins>~~.~~</ins>
|
||||||
|
|
||||||
|
## Цвета
|
||||||
|
|
||||||
|
Цвет текста задается при помощи цветового кода: [#RRGGBB]
|
||||||
|
|
||||||
|
| Компонент | Назначение |
|
||||||
|
| ------------ | ------------------------- |
|
||||||
|
| R | Используется для интенсивности красного |
|
||||||
|
| G | Используется для интенсивности зеленого |
|
||||||
|
| B | Используется для интенсивности синего |
|
||||||
|
|
||||||
|
### Например:
|
||||||
|
|
||||||
|
<span style="color: #ff0000">
|
||||||
|
<span style="color:rgb(105, 105, 105)">
|
||||||
|
[#ff0000]
|
||||||
|
</span>Красный Текст
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span style="color: #00ff00">
|
||||||
|
<span style="color:rgb(105, 105, 105)">
|
||||||
|
[#00ff00]
|
||||||
|
</span>Зеленый Текст
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span style="color: #0000ff">
|
||||||
|
<span style="color:rgb(105, 105, 105)">
|
||||||
|
[#0000ff]
|
||||||
|
</span>Синий Текст
|
||||||
|
</span>
|
||||||
@ -1,15 +1,9 @@
|
|||||||
#include "markdown.hpp"
|
#include "markdown.hpp"
|
||||||
|
#include "coders/commons.hpp"
|
||||||
#include "graphics/core/Font.hpp"
|
#include "graphics/core/Font.hpp"
|
||||||
|
|
||||||
using namespace markdown;
|
using namespace markdown;
|
||||||
|
|
||||||
static inline int hexchar2int(char c) {
|
|
||||||
if (c >= '0' && c <= '9') return c - '0';
|
|
||||||
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
|
||||||
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename CharT>
|
template <typename CharT>
|
||||||
static inline void emit(
|
static inline void emit(
|
||||||
CharT c, FontStylesScheme& styles, std::basic_stringstream<CharT>& ss
|
CharT c, FontStylesScheme& styles, std::basic_stringstream<CharT>& ss
|
||||||
@ -28,7 +22,7 @@ static inline void emit_md(
|
|||||||
|
|
||||||
template <typename CharT>
|
template <typename CharT>
|
||||||
static glm::vec4 parse_color(const std::basic_string_view<CharT>& color_code) {
|
static glm::vec4 parse_color(const std::basic_string_view<CharT>& color_code) {
|
||||||
if (color_code.size() != 9 || color_code[0] != '#') {
|
if (color_code.size() != 8 || color_code[0] != '#') {
|
||||||
return glm::vec4(1, 1, 1, 1); // default to white
|
return glm::vec4(1, 1, 1, 1); // default to white
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +39,7 @@ static glm::vec4 parse_color(const std::basic_string_view<CharT>& color_code) {
|
|||||||
hex_to_float(color_code[1], color_code[2]),
|
hex_to_float(color_code[1], color_code[2]),
|
||||||
hex_to_float(color_code[3], color_code[4]),
|
hex_to_float(color_code[3], color_code[4]),
|
||||||
hex_to_float(color_code[5], color_code[6]),
|
hex_to_float(color_code[5], color_code[6]),
|
||||||
hex_to_float(color_code[7], color_code[8])
|
1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,15 +81,15 @@ Result<CharT> process_markdown(
|
|||||||
while (pos < source.size()) {
|
while (pos < source.size()) {
|
||||||
CharT first = source[pos];
|
CharT first = source[pos];
|
||||||
|
|
||||||
if (first == '[' && pos + 10 < source.size() && source[pos + 1] == '#' && source[pos + 9] == ']') {
|
if (first == '[' && pos + 9 < source.size() && source[pos + 1] == '#' && source[pos + 8] == ']') {
|
||||||
std::basic_string_view<CharT> color_code = source.substr(pos + 1, 9);
|
std::basic_string_view<CharT> color_code = source.substr(pos + 1, 8);
|
||||||
apply_color(color_code, styles);
|
apply_color(color_code, styles);
|
||||||
if (!eraseMarkdown) {
|
if (!eraseMarkdown) {
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
emit_md(source[pos + i], styles, ss);
|
emit_md(source[pos + i], styles, ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pos += 10; // Skip past the color code
|
pos += 9; // Skip past the color code
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user