mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-20 03:43:52 +00:00
Improve the look of new version release notes (#12231)
# Description Adds md4c to parse release notes to HTML # Screenshots/Recordings/Graphs <img width="695" height="580" alt="image" src="https://github.com/user-attachments/assets/8eaf2874-34f8-479a-b38c-2f9754297299" /> ## Tests Tested on Windows
This commit is contained in:
@@ -26,6 +26,7 @@ add_subdirectory(imguizmo)
|
|||||||
add_subdirectory(libigl)
|
add_subdirectory(libigl)
|
||||||
add_subdirectory(libnest2d)
|
add_subdirectory(libnest2d)
|
||||||
add_subdirectory(mcut)
|
add_subdirectory(mcut)
|
||||||
|
add_subdirectory(md4c)
|
||||||
add_subdirectory(miniz)
|
add_subdirectory(miniz)
|
||||||
add_subdirectory(minilzo)
|
add_subdirectory(minilzo)
|
||||||
add_subdirectory(qhull)
|
add_subdirectory(qhull)
|
||||||
|
|||||||
71
deps_src/md4c/CMakeLists.txt
Normal file
71
deps_src/md4c/CMakeLists.txt
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
project(MD4C C)
|
||||||
|
|
||||||
|
set(MD_VERSION_MAJOR 0)
|
||||||
|
set(MD_VERSION_MINOR 5)
|
||||||
|
set(MD_VERSION_RELEASE 2)
|
||||||
|
set(MD_VERSION "${MD_VERSION_MAJOR}.${MD_VERSION_MINOR}.${MD_VERSION_RELEASE}")
|
||||||
|
|
||||||
|
set(PROJECT_VERSION "${MD_VERSION}")
|
||||||
|
set(PROJECT_URL "https://github.com/mity/md4c")
|
||||||
|
|
||||||
|
|
||||||
|
#option(BUILD_MD2HTML_EXECUTABLE "Whether to compile the md2html executable" ON)
|
||||||
|
|
||||||
|
|
||||||
|
#if(WIN32)
|
||||||
|
# # On Windows, given there is no standard lib install dir etc., we rather
|
||||||
|
# # by default build static lib.
|
||||||
|
# option(BUILD_SHARED_LIBS "help string describing option" OFF)
|
||||||
|
#else()
|
||||||
|
# # On Linux, MD4C is slowly being adding into some distros which prefer
|
||||||
|
# # shared lib.
|
||||||
|
# option(BUILD_SHARED_LIBS "help string describing option" ON)
|
||||||
|
#endif()
|
||||||
|
|
||||||
|
add_definitions(
|
||||||
|
-DMD_VERSION_MAJOR=${MD_VERSION_MAJOR}
|
||||||
|
-DMD_VERSION_MINOR=${MD_VERSION_MINOR}
|
||||||
|
-DMD_VERSION_RELEASE=${MD_VERSION_RELEASE}
|
||||||
|
)
|
||||||
|
|
||||||
|
#set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo MinSizeRel)
|
||||||
|
#if("${CMAKE_BUILD_TYPE}" STREQUAL "")
|
||||||
|
# set(CMAKE_BUILD_TYPE $ENV{CMAKE_BUILD_TYPE})
|
||||||
|
#
|
||||||
|
# if("${CMAKE_BUILD_TYPE}" STREQUAL "")
|
||||||
|
# set(CMAKE_BUILD_TYPE "Release")
|
||||||
|
# endif()
|
||||||
|
#endif()
|
||||||
|
|
||||||
|
|
||||||
|
if(${CMAKE_C_COMPILER_ID} MATCHES GNU|Clang)
|
||||||
|
add_compile_options(-Wall -Wextra -Wshadow)
|
||||||
|
|
||||||
|
# We enforce -Wdeclaration-after-statement because Qt project needs to
|
||||||
|
# build MD4C with Integrity compiler which chokes whenever a declaration
|
||||||
|
# is not at the beginning of a block.
|
||||||
|
add_compile_options(-Wdeclaration-after-statement)
|
||||||
|
elseif(MSVC)
|
||||||
|
# Disable warnings about the so-called unsecured functions:
|
||||||
|
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
||||||
|
add_compile_options(/W3)
|
||||||
|
|
||||||
|
# Specify proper C runtime library:
|
||||||
|
string(REGEX REPLACE "/M[DT]d?" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
|
||||||
|
string(REGEX REPLACE "/M[DT]d?" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
|
||||||
|
string(REGEX REPLACE "/M[DT]d?" "" CMAKE_C_FLAGS_RELWITHDEBINFO "{$CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
||||||
|
string(REGEX REPLACE "/M[DT]d?" "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
|
||||||
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
|
||||||
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} /MT")
|
||||||
|
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_RELEASE} /MT")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
add_subdirectory(src)
|
||||||
|
#if (BUILD_MD2HTML_EXECUTABLE)
|
||||||
|
# add_subdirectory(md2html)
|
||||||
|
#endif ()
|
||||||
22
deps_src/md4c/LICENSE.md
Normal file
22
deps_src/md4c/LICENSE.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
# The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright © 2016-2024 Martin Mitáš
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the “Software”),
|
||||||
|
to deal in the Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
IN THE SOFTWARE.
|
||||||
297
deps_src/md4c/README.md
Normal file
297
deps_src/md4c/README.md
Normal file
@@ -0,0 +1,297 @@
|
|||||||
|
|
||||||
|
# MD4C Readme
|
||||||
|
|
||||||
|
* Home: http://github.com/mity/md4c
|
||||||
|
* Wiki: http://github.com/mity/md4c/wiki
|
||||||
|
* Issue tracker: http://github.com/mity/md4c/issues
|
||||||
|
|
||||||
|
MD4C stands for "Markdown for C" and that's exactly what this project is about.
|
||||||
|
|
||||||
|
|
||||||
|
## What is Markdown
|
||||||
|
|
||||||
|
In short, Markdown is the markup language this `README.md` file is written in.
|
||||||
|
|
||||||
|
The following resources can explain more if you are unfamiliar with it:
|
||||||
|
* [Wikipedia article](http://en.wikipedia.org/wiki/Markdown)
|
||||||
|
* [CommonMark site](http://commonmark.org)
|
||||||
|
|
||||||
|
|
||||||
|
## What is MD4C
|
||||||
|
|
||||||
|
MD4C is Markdown parser implementation in C, with the following features:
|
||||||
|
|
||||||
|
* **Compliance:** Generally, MD4C aims to be compliant to the latest version of
|
||||||
|
[CommonMark specification](http://spec.commonmark.org/). Currently, we are
|
||||||
|
fully compliant to CommonMark 0.31.
|
||||||
|
|
||||||
|
* **Extensions:** MD4C supports some commonly requested and accepted extensions.
|
||||||
|
See below.
|
||||||
|
|
||||||
|
* **Performance:** MD4C is [very fast](https://talk.commonmark.org/t/2520).
|
||||||
|
|
||||||
|
* **Compactness:** MD4C parser is implemented in one source file and one header
|
||||||
|
file. There are no dependencies other than standard C library.
|
||||||
|
|
||||||
|
* **Embedding:** MD4C parser is easy to reuse in other projects, its API is
|
||||||
|
very straightforward: There is actually just one function, `md_parse()`.
|
||||||
|
|
||||||
|
* **Push model:** MD4C parses the complete document and calls few callback
|
||||||
|
functions provided by the application to inform it about a start/end of
|
||||||
|
every block, a start/end of every span, and with any textual contents.
|
||||||
|
|
||||||
|
* **Portability:** MD4C builds and works on Windows and POSIX-compliant OSes.
|
||||||
|
(It should be simple to make it run also on most other platforms, at least as
|
||||||
|
long as the platform provides C standard library, including a heap memory
|
||||||
|
management.)
|
||||||
|
|
||||||
|
* **Encoding:** MD4C by default expects UTF-8 encoding of the input document.
|
||||||
|
But it can be compiled to recognize ASCII-only control characters (i.e. to
|
||||||
|
disable all Unicode-specific code), or (on Windows) to expect UTF-16 (i.e.
|
||||||
|
what is on Windows commonly called just "Unicode"). See more details below.
|
||||||
|
|
||||||
|
* **Permissive license:** MD4C is available under the [MIT license](LICENSE.md).
|
||||||
|
|
||||||
|
|
||||||
|
## Using MD4C
|
||||||
|
|
||||||
|
### Parsing Markdown
|
||||||
|
|
||||||
|
If you need just to parse a Markdown document, you need to include `md4c.h`
|
||||||
|
and link against MD4C library (`-lmd4c`); or alternatively add `md4c.[hc]`
|
||||||
|
directly to your code base as the parser is only implemented in the single C
|
||||||
|
source file.
|
||||||
|
|
||||||
|
The main provided function is `md_parse()`. It takes a text in the Markdown
|
||||||
|
syntax and a pointer to a structure which provides pointers to several callback
|
||||||
|
functions.
|
||||||
|
|
||||||
|
As `md_parse()` processes the input, it calls the callbacks (when entering or
|
||||||
|
leaving any Markdown block or span; and when outputting any textual content of
|
||||||
|
the document), allowing application to convert it into another format or render
|
||||||
|
it onto the screen.
|
||||||
|
|
||||||
|
|
||||||
|
### Converting to HTML
|
||||||
|
|
||||||
|
If you need to convert Markdown to HTML, include `md4c-html.h` and link against
|
||||||
|
MD4C-HTML library (`-lmd4c-html`); or alternatively add the sources `md4c.[hc]`,
|
||||||
|
`md4c-html.[hc]` and `entity.[hc]` into your code base.
|
||||||
|
|
||||||
|
To convert a Markdown input, call `md_html()` function. It takes the Markdown
|
||||||
|
input and calls the provided callback function. The callback is fed with
|
||||||
|
chunks of the HTML output. Typical callback implementation just appends the
|
||||||
|
chunks into a buffer or writes them to a file.
|
||||||
|
|
||||||
|
|
||||||
|
## Markdown Extensions
|
||||||
|
|
||||||
|
The default behavior is to recognize only Markdown syntax defined by the
|
||||||
|
[CommonMark specification](http://spec.commonmark.org/).
|
||||||
|
|
||||||
|
However, with appropriate flags, the behavior can be tuned to enable some
|
||||||
|
extensions:
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_COLLAPSEWHITESPACE`, a non-trivial whitespace is
|
||||||
|
collapsed into a single space.
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_TABLES`, GitHub-style tables are supported.
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_TASKLISTS`, GitHub-style task lists are supported.
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_STRIKETHROUGH`, strike-through spans are enabled
|
||||||
|
(text enclosed in tilde marks, e.g. `~foo bar~`).
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_PERMISSIVEURLAUTOLINKS` permissive URL autolinks
|
||||||
|
(not enclosed in `<` and `>`) are supported.
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_PERMISSIVEEMAILAUTOLINKS`, permissive e-mail
|
||||||
|
autolinks (not enclosed in `<` and `>`) are supported.
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_PERMISSIVEWWWAUTOLINKS` permissive WWW autolinks
|
||||||
|
without any scheme specified (e.g. `www.example.com`) are supported. MD4C
|
||||||
|
then assumes `http:` scheme.
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_LATEXMATHSPANS` LaTeX math spans (`$...$`) and
|
||||||
|
LaTeX display math spans (`$$...$$`) are supported. (Note though that the
|
||||||
|
HTML renderer outputs them verbatim in a custom tag `<x-equation>`.)
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_WIKILINKS`, wiki-style links (`[[link label]]` and
|
||||||
|
`[[target article|link label]]`) are supported. (Note that the HTML renderer
|
||||||
|
outputs them in a custom tag `<x-wikilink>`.)
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_UNDERLINE`, underscore (`_`) denotes an underline
|
||||||
|
instead of an ordinary emphasis or strong emphasis.
|
||||||
|
|
||||||
|
Few features of CommonMark (those some people see as mis-features) may be
|
||||||
|
disabled with the following flags:
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_NOHTMLSPANS` or `MD_FLAG_NOHTMLBLOCKS`, raw inline
|
||||||
|
HTML or raw HTML blocks respectively are disabled.
|
||||||
|
|
||||||
|
* With the flag `MD_FLAG_NOINDENTEDCODEBLOCKS`, indented code blocks are
|
||||||
|
disabled.
|
||||||
|
|
||||||
|
|
||||||
|
## Input/Output Encoding
|
||||||
|
|
||||||
|
The CommonMark specification declares that any sequence of Unicode code points
|
||||||
|
is a valid CommonMark document.
|
||||||
|
|
||||||
|
But, under a closer inspection, Unicode plays any role in few very specific
|
||||||
|
situations when parsing Markdown documents:
|
||||||
|
|
||||||
|
1. For detection of word boundaries when processing emphasis and strong
|
||||||
|
emphasis, some classification of Unicode characters (whether it is
|
||||||
|
a whitespace or a punctuation) is needed.
|
||||||
|
|
||||||
|
2. For (case-insensitive) matching of a link reference label with the
|
||||||
|
corresponding link reference definition, Unicode case folding is used.
|
||||||
|
|
||||||
|
3. For translating HTML entities (e.g. `&`) and numeric character
|
||||||
|
references (e.g. `#` or `ಫ`) into their Unicode equivalents.
|
||||||
|
|
||||||
|
However note MD4C leaves this translation on the renderer/application; as
|
||||||
|
the renderer is supposed to really know output encoding and whether it
|
||||||
|
really needs to perform this kind of translation. (For example, when the
|
||||||
|
renderer outputs HTML, it may leave the entities untranslated and defer the
|
||||||
|
work to a web browser.)
|
||||||
|
|
||||||
|
MD4C relies on this property of the CommonMark and the implementation is, to
|
||||||
|
a large degree, encoding-agnostic. Most of MD4C code only assumes that the
|
||||||
|
encoding of your choice is compatible with ASCII. I.e. that the codepoints
|
||||||
|
below 128 have the same numeric values as ASCII.
|
||||||
|
|
||||||
|
Any input MD4C does not understand is simply seen as part of the document text
|
||||||
|
and sent to the renderer's callback functions unchanged.
|
||||||
|
|
||||||
|
The two situations (word boundary detection and link reference matching) where
|
||||||
|
MD4C has to understand Unicode are handled as specified by the following
|
||||||
|
preprocessor macros (as specified at the time MD4C is being built):
|
||||||
|
|
||||||
|
* If preprocessor macro `MD4C_USE_UTF8` is defined, MD4C assumes UTF-8 for the
|
||||||
|
word boundary detection and for the case-insensitive matching of link labels.
|
||||||
|
|
||||||
|
When none of these macros is explicitly used, this is the default behavior.
|
||||||
|
|
||||||
|
* On Windows, if preprocessor macro `MD4C_USE_UTF16` is defined, MD4C uses
|
||||||
|
`WCHAR` instead of `char` and assumes UTF-16 encoding in those situations.
|
||||||
|
(UTF-16 is what Windows developers usually call just "Unicode" and what
|
||||||
|
Win32API generally works with.)
|
||||||
|
|
||||||
|
Note that because this macro affects also the types in `md4c.h`, you have
|
||||||
|
to define the macro both when building MD4C as well as when including
|
||||||
|
`md4c.h`.
|
||||||
|
|
||||||
|
Also note this is only supported in the parser (`md4c.[hc]`). The HTML
|
||||||
|
renderer does not support this and you will have to write your own custom
|
||||||
|
renderer to use this feature.
|
||||||
|
|
||||||
|
* If preprocessor macro `MD4C_USE_ASCII` is defined, MD4C assumes nothing but
|
||||||
|
an ASCII input.
|
||||||
|
|
||||||
|
That effectively means that non-ASCII whitespace or punctuation characters
|
||||||
|
won't be recognized as such and that link reference matching will work in
|
||||||
|
a case-insensitive way only for ASCII letters (`[a-zA-Z]`).
|
||||||
|
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
The API of the parser is quite well documented in the comments in the `md4c.h`.
|
||||||
|
Similarly, the markdown-to-html API is described in its header `md4c-html.h`.
|
||||||
|
|
||||||
|
There is also [project wiki](http://github.com/mity/md4c/wiki) which provides
|
||||||
|
some more comprehensive documentation. However note it is incomplete and some
|
||||||
|
details may be somewhat outdated.
|
||||||
|
|
||||||
|
|
||||||
|
## FAQ
|
||||||
|
|
||||||
|
**Q: How does MD4C compare to other Markdown parsers?**
|
||||||
|
|
||||||
|
**A:** Some other implementations combine Markdown parser and HTML generator
|
||||||
|
into a single entangled code hidden behind an interface which just allows the
|
||||||
|
conversion from Markdown to HTML. They are often unusable if you want to
|
||||||
|
process the input in any other way.
|
||||||
|
|
||||||
|
Second, most parsers (if not all of them; at least within the scope of C/C++
|
||||||
|
language) are full DOM-like parsers: They construct abstract syntax tree (AST)
|
||||||
|
representation of the whole Markdown document. That takes time and it leads to
|
||||||
|
bigger memory footprint.
|
||||||
|
|
||||||
|
Building AST is completely fine as long as you need it. If you don't, there is
|
||||||
|
a very high chance that using MD4C will be substantially faster and less hungry
|
||||||
|
in terms of memory consumption.
|
||||||
|
|
||||||
|
Last but not least, some Markdown parsers are implemented in a naive way. When
|
||||||
|
fed with a [smartly crafted input pattern](test/pathological_tests.py), they
|
||||||
|
may exhibit quadratic (or even worse) parsing times. What MD4C can still parse
|
||||||
|
in a fraction of second may turn into long minutes or possibly hours with them.
|
||||||
|
Hence, when such a naive parser is used to process an input from an untrusted
|
||||||
|
source, the possibility of denial-of-service attacks becomes a real danger.
|
||||||
|
|
||||||
|
A lot of our effort went into providing linear parsing times no matter what
|
||||||
|
kind of crazy input MD4C parser is fed with. (If you encounter an input pattern
|
||||||
|
which leads to a sub-linear parsing times, please do not hesitate and report it
|
||||||
|
as a bug.)
|
||||||
|
|
||||||
|
**Q: Does MD4C perform any input validation?**
|
||||||
|
|
||||||
|
**A:** No. And we are proud of it. :-)
|
||||||
|
|
||||||
|
CommonMark specification states that any sequence of Unicode characters is
|
||||||
|
a valid Markdown document. (In practice, this more or less always means UTF-8
|
||||||
|
encoding.)
|
||||||
|
|
||||||
|
In other words, according to the specification, it does not matter whether some
|
||||||
|
Markdown syntax construction is in some way broken or not. If it's broken, it
|
||||||
|
won't be recognized and the parser should see it just as a verbatim text.
|
||||||
|
|
||||||
|
MD4C takes this a step further: It sees any sequence of bytes as a valid input,
|
||||||
|
following completely the GIGO philosophy (garbage in, garbage out). I.e. any
|
||||||
|
ill-formed UTF-8 byte sequence will propagate to the respective callback as
|
||||||
|
a part of the text.
|
||||||
|
|
||||||
|
If you need to validate that the input is, say, a well-formed UTF-8 document,
|
||||||
|
you have to do it on your own. The easiest way how to do this is to simply
|
||||||
|
validate the whole document before passing it to the MD4C parser.
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MD4C is covered with MIT license, see the file `LICENSE.md`.
|
||||||
|
|
||||||
|
|
||||||
|
## Links to Related Projects
|
||||||
|
|
||||||
|
Ports and bindings to other languages:
|
||||||
|
|
||||||
|
* [commonmark-d](https://github.com/AuburnSounds/commonmark-d):
|
||||||
|
Port of MD4C to D language.
|
||||||
|
|
||||||
|
* [markdown-wasm](https://github.com/rsms/markdown-wasm):
|
||||||
|
Port of MD4C to WebAssembly.
|
||||||
|
|
||||||
|
* [PyMD4C](https://github.com/dominickpastore/pymd4c):
|
||||||
|
Python bindings for MD4C
|
||||||
|
|
||||||
|
Software using MD4C:
|
||||||
|
|
||||||
|
* [imgui_md](https://github.com/mekhontsev/imgui_md):
|
||||||
|
Markdown renderer for [Dear ImGui](https://github.com/ocornut/imgui)
|
||||||
|
|
||||||
|
* [MarkDown Monolith Assembler](https://github.com/1Hyena/mdma):
|
||||||
|
A command line tool for building browser-based books.
|
||||||
|
|
||||||
|
* [QOwnNotes](https://www.qownnotes.org/):
|
||||||
|
A plain-text file notepad and todo-list manager with markdown support and
|
||||||
|
ownCloud / Nextcloud integration.
|
||||||
|
|
||||||
|
* [Qt](https://www.qt.io/):
|
||||||
|
Cross-platform C++ GUI framework.
|
||||||
|
|
||||||
|
* [Textosaurus](https://github.com/martinrotter/textosaurus):
|
||||||
|
Cross-platform text editor based on Qt and Scintilla.
|
||||||
|
|
||||||
|
* [8th](https://8th-dev.com/):
|
||||||
|
Cross-platform concatenative programming language.
|
||||||
53
deps_src/md4c/src/CMakeLists.txt
Normal file
53
deps_src/md4c/src/CMakeLists.txt
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1)
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
|
||||||
|
|
||||||
|
|
||||||
|
# Build rules for MD4C parser library
|
||||||
|
|
||||||
|
configure_file(md4c.pc.in md4c.pc @ONLY)
|
||||||
|
add_library(md4c md4c.c md4c.h)
|
||||||
|
set_target_properties(md4c PROPERTIES
|
||||||
|
COMPILE_FLAGS "-DMD4C_USE_UTF8"
|
||||||
|
VERSION ${MD_VERSION}
|
||||||
|
SOVERSION ${MD_VERSION_MAJOR}
|
||||||
|
PUBLIC_HEADER md4c.h
|
||||||
|
)
|
||||||
|
|
||||||
|
# Build rules for HTML renderer library
|
||||||
|
|
||||||
|
configure_file(md4c-html.pc.in md4c-html.pc @ONLY)
|
||||||
|
add_library(md4c-html md4c-html.c md4c-html.h entity.c entity.h)
|
||||||
|
set_target_properties(md4c-html PROPERTIES
|
||||||
|
VERSION ${MD_VERSION}
|
||||||
|
SOVERSION ${MD_VERSION_MAJOR}
|
||||||
|
PUBLIC_HEADER md4c-html.h
|
||||||
|
)
|
||||||
|
target_link_libraries(md4c-html md4c)
|
||||||
|
|
||||||
|
|
||||||
|
# Install rules
|
||||||
|
|
||||||
|
#install(
|
||||||
|
# TARGETS md4c
|
||||||
|
# EXPORT md4cConfig
|
||||||
|
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
# PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
# INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
#)
|
||||||
|
#install(FILES ${CMAKE_BINARY_DIR}/src/md4c.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||||
|
#
|
||||||
|
#install(
|
||||||
|
# TARGETS md4c-html
|
||||||
|
# EXPORT md4cConfig
|
||||||
|
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
# PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
#)
|
||||||
|
#install(FILES ${CMAKE_BINARY_DIR}/src/md4c-html.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||||
|
#
|
||||||
|
#install(EXPORT md4cConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/md4c/ NAMESPACE md4c::)
|
||||||
|
#
|
||||||
2185
deps_src/md4c/src/entity.c
Normal file
2185
deps_src/md4c/src/entity.c
Normal file
File diff suppressed because it is too large
Load Diff
43
deps_src/md4c/src/entity.h
Normal file
43
deps_src/md4c/src/entity.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* MD4C: Markdown parser for C
|
||||||
|
* (http://github.com/mity/md4c)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016-2024 Martin Mitáš
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MD4C_ENTITY_H
|
||||||
|
#define MD4C_ENTITY_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Most entities are formed by single Unicode codepoint, few by two codepoints.
|
||||||
|
* Single-codepoint entities have codepoints[1] set to zero. */
|
||||||
|
typedef struct ENTITY_tag ENTITY;
|
||||||
|
struct ENTITY_tag {
|
||||||
|
const char* name;
|
||||||
|
unsigned codepoints[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
const ENTITY* entity_lookup(const char* name, size_t name_size);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* MD4C_ENTITY_H */
|
||||||
567
deps_src/md4c/src/md4c-html.c
Normal file
567
deps_src/md4c/src/md4c-html.c
Normal file
@@ -0,0 +1,567 @@
|
|||||||
|
/*
|
||||||
|
* MD4C: Markdown parser for C
|
||||||
|
* (http://github.com/mity/md4c)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016-2024 Martin Mitáš
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "md4c-html.h"
|
||||||
|
#include "entity.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199409L
|
||||||
|
/* C89/90 or old compilers in general may not understand "inline". */
|
||||||
|
#if defined __GNUC__
|
||||||
|
#define inline __inline__
|
||||||
|
#elif defined _MSC_VER
|
||||||
|
#define inline __inline
|
||||||
|
#else
|
||||||
|
#define inline
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define snprintf _snprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct MD_HTML_tag MD_HTML;
|
||||||
|
struct MD_HTML_tag {
|
||||||
|
void (*process_output)(const MD_CHAR*, MD_SIZE, void*);
|
||||||
|
void* userdata;
|
||||||
|
unsigned flags;
|
||||||
|
int image_nesting_level;
|
||||||
|
char escape_map[256];
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NEED_HTML_ESC_FLAG 0x1
|
||||||
|
#define NEED_URL_ESC_FLAG 0x2
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************
|
||||||
|
*** HTML rendering helper functions ***
|
||||||
|
*****************************************/
|
||||||
|
|
||||||
|
#define ISDIGIT(ch) ('0' <= (ch) && (ch) <= '9')
|
||||||
|
#define ISLOWER(ch) ('a' <= (ch) && (ch) <= 'z')
|
||||||
|
#define ISUPPER(ch) ('A' <= (ch) && (ch) <= 'Z')
|
||||||
|
#define ISALNUM(ch) (ISLOWER(ch) || ISUPPER(ch) || ISDIGIT(ch))
|
||||||
|
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
render_verbatim(MD_HTML* r, const MD_CHAR* text, MD_SIZE size)
|
||||||
|
{
|
||||||
|
r->process_output(text, size, r->userdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keep this as a macro. Most compiler should then be smart enough to replace
|
||||||
|
* the strlen() call with a compile-time constant if the string is a C literal. */
|
||||||
|
#define RENDER_VERBATIM(r, verbatim) \
|
||||||
|
render_verbatim((r), (verbatim), (MD_SIZE) (strlen(verbatim)))
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_html_escaped(MD_HTML* r, const MD_CHAR* data, MD_SIZE size)
|
||||||
|
{
|
||||||
|
MD_OFFSET beg = 0;
|
||||||
|
MD_OFFSET off = 0;
|
||||||
|
|
||||||
|
/* Some characters need to be escaped in normal HTML text. */
|
||||||
|
#define NEED_HTML_ESC(ch) (r->escape_map[(unsigned char)(ch)] & NEED_HTML_ESC_FLAG)
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
/* Optimization: Use some loop unrolling. */
|
||||||
|
while(off + 3 < size && !NEED_HTML_ESC(data[off+0]) && !NEED_HTML_ESC(data[off+1])
|
||||||
|
&& !NEED_HTML_ESC(data[off+2]) && !NEED_HTML_ESC(data[off+3]))
|
||||||
|
off += 4;
|
||||||
|
while(off < size && !NEED_HTML_ESC(data[off]))
|
||||||
|
off++;
|
||||||
|
|
||||||
|
if(off > beg)
|
||||||
|
render_verbatim(r, data + beg, off - beg);
|
||||||
|
|
||||||
|
if(off < size) {
|
||||||
|
switch(data[off]) {
|
||||||
|
case '&': RENDER_VERBATIM(r, "&"); break;
|
||||||
|
case '<': RENDER_VERBATIM(r, "<"); break;
|
||||||
|
case '>': RENDER_VERBATIM(r, ">"); break;
|
||||||
|
case '"': RENDER_VERBATIM(r, """); break;
|
||||||
|
}
|
||||||
|
off++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
beg = off;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_url_escaped(MD_HTML* r, const MD_CHAR* data, MD_SIZE size)
|
||||||
|
{
|
||||||
|
static const MD_CHAR hex_chars[] = "0123456789ABCDEF";
|
||||||
|
MD_OFFSET beg = 0;
|
||||||
|
MD_OFFSET off = 0;
|
||||||
|
|
||||||
|
/* Some characters need to be escaped in URL attributes. */
|
||||||
|
#define NEED_URL_ESC(ch) (r->escape_map[(unsigned char)(ch)] & NEED_URL_ESC_FLAG)
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
while(off < size && !NEED_URL_ESC(data[off]))
|
||||||
|
off++;
|
||||||
|
if(off > beg)
|
||||||
|
render_verbatim(r, data + beg, off - beg);
|
||||||
|
|
||||||
|
if(off < size) {
|
||||||
|
char hex[3];
|
||||||
|
|
||||||
|
switch(data[off]) {
|
||||||
|
case '&': RENDER_VERBATIM(r, "&"); break;
|
||||||
|
default:
|
||||||
|
hex[0] = '%';
|
||||||
|
hex[1] = hex_chars[((unsigned)data[off] >> 4) & 0xf];
|
||||||
|
hex[2] = hex_chars[((unsigned)data[off] >> 0) & 0xf];
|
||||||
|
render_verbatim(r, hex, 3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
off++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
beg = off;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned
|
||||||
|
hex_val(char ch)
|
||||||
|
{
|
||||||
|
if('0' <= ch && ch <= '9')
|
||||||
|
return ch - '0';
|
||||||
|
if('A' <= ch && ch <= 'Z')
|
||||||
|
return ch - 'A' + 10;
|
||||||
|
else
|
||||||
|
return ch - 'a' + 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_utf8_codepoint(MD_HTML* r, unsigned codepoint,
|
||||||
|
void (*fn_append)(MD_HTML*, const MD_CHAR*, MD_SIZE))
|
||||||
|
{
|
||||||
|
static const MD_CHAR utf8_replacement_char[] = { (char)0xef, (char)0xbf, (char)0xbd };
|
||||||
|
|
||||||
|
unsigned char utf8[4];
|
||||||
|
size_t n;
|
||||||
|
|
||||||
|
if(codepoint <= 0x7f) {
|
||||||
|
n = 1;
|
||||||
|
utf8[0] = codepoint;
|
||||||
|
} else if(codepoint <= 0x7ff) {
|
||||||
|
n = 2;
|
||||||
|
utf8[0] = 0xc0 | ((codepoint >> 6) & 0x1f);
|
||||||
|
utf8[1] = 0x80 + ((codepoint >> 0) & 0x3f);
|
||||||
|
} else if(codepoint <= 0xffff) {
|
||||||
|
n = 3;
|
||||||
|
utf8[0] = 0xe0 | ((codepoint >> 12) & 0xf);
|
||||||
|
utf8[1] = 0x80 + ((codepoint >> 6) & 0x3f);
|
||||||
|
utf8[2] = 0x80 + ((codepoint >> 0) & 0x3f);
|
||||||
|
} else {
|
||||||
|
n = 4;
|
||||||
|
utf8[0] = 0xf0 | ((codepoint >> 18) & 0x7);
|
||||||
|
utf8[1] = 0x80 + ((codepoint >> 12) & 0x3f);
|
||||||
|
utf8[2] = 0x80 + ((codepoint >> 6) & 0x3f);
|
||||||
|
utf8[3] = 0x80 + ((codepoint >> 0) & 0x3f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(0 < codepoint && codepoint <= 0x10ffff)
|
||||||
|
fn_append(r, (char*)utf8, (MD_SIZE)n);
|
||||||
|
else
|
||||||
|
fn_append(r, utf8_replacement_char, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Translate entity to its UTF-8 equivalent, or output the verbatim one
|
||||||
|
* if such entity is unknown (or if the translation is disabled). */
|
||||||
|
static void
|
||||||
|
render_entity(MD_HTML* r, const MD_CHAR* text, MD_SIZE size,
|
||||||
|
void (*fn_append)(MD_HTML*, const MD_CHAR*, MD_SIZE))
|
||||||
|
{
|
||||||
|
if(r->flags & MD_HTML_FLAG_VERBATIM_ENTITIES) {
|
||||||
|
render_verbatim(r, text, size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We assume UTF-8 output is what is desired. */
|
||||||
|
if(size > 3 && text[1] == '#') {
|
||||||
|
unsigned codepoint = 0;
|
||||||
|
|
||||||
|
if(text[2] == 'x' || text[2] == 'X') {
|
||||||
|
/* Hexadecimal entity (e.g. "�")). */
|
||||||
|
MD_SIZE i;
|
||||||
|
for(i = 3; i < size-1; i++)
|
||||||
|
codepoint = 16 * codepoint + hex_val(text[i]);
|
||||||
|
} else {
|
||||||
|
/* Decimal entity (e.g. "&1234;") */
|
||||||
|
MD_SIZE i;
|
||||||
|
for(i = 2; i < size-1; i++)
|
||||||
|
codepoint = 10 * codepoint + (text[i] - '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
render_utf8_codepoint(r, codepoint, fn_append);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
/* Named entity (e.g. " "). */
|
||||||
|
const ENTITY* ent;
|
||||||
|
|
||||||
|
ent = entity_lookup(text, size);
|
||||||
|
if(ent != NULL) {
|
||||||
|
render_utf8_codepoint(r, ent->codepoints[0], fn_append);
|
||||||
|
if(ent->codepoints[1])
|
||||||
|
render_utf8_codepoint(r, ent->codepoints[1], fn_append);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn_append(r, text, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_attribute(MD_HTML* r, const MD_ATTRIBUTE* attr,
|
||||||
|
void (*fn_append)(MD_HTML*, const MD_CHAR*, MD_SIZE))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; attr->substr_offsets[i] < attr->size; i++) {
|
||||||
|
MD_TEXTTYPE type = attr->substr_types[i];
|
||||||
|
MD_OFFSET off = attr->substr_offsets[i];
|
||||||
|
MD_SIZE size = attr->substr_offsets[i+1] - off;
|
||||||
|
const MD_CHAR* text = attr->text + off;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case MD_TEXT_NULLCHAR: render_utf8_codepoint(r, 0x0000, render_verbatim); break;
|
||||||
|
case MD_TEXT_ENTITY: render_entity(r, text, size, fn_append); break;
|
||||||
|
default: fn_append(r, text, size); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_open_ol_block(MD_HTML* r, const MD_BLOCK_OL_DETAIL* det)
|
||||||
|
{
|
||||||
|
char buf[64];
|
||||||
|
|
||||||
|
if(det->start == 1) {
|
||||||
|
RENDER_VERBATIM(r, "<ol>\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "<ol start=\"%u\">\n", det->start);
|
||||||
|
RENDER_VERBATIM(r, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_open_li_block(MD_HTML* r, const MD_BLOCK_LI_DETAIL* det)
|
||||||
|
{
|
||||||
|
if(det->is_task) {
|
||||||
|
RENDER_VERBATIM(r, "<li class=\"task-list-item\">"
|
||||||
|
"<input type=\"checkbox\" class=\"task-list-item-checkbox\" disabled");
|
||||||
|
if(det->task_mark == 'x' || det->task_mark == 'X')
|
||||||
|
RENDER_VERBATIM(r, " checked");
|
||||||
|
RENDER_VERBATIM(r, ">");
|
||||||
|
} else {
|
||||||
|
RENDER_VERBATIM(r, "<li>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_open_code_block(MD_HTML* r, const MD_BLOCK_CODE_DETAIL* det)
|
||||||
|
{
|
||||||
|
RENDER_VERBATIM(r, "<pre><code");
|
||||||
|
|
||||||
|
/* If known, output the HTML 5 attribute class="language-LANGNAME". */
|
||||||
|
if(det->lang.text != NULL) {
|
||||||
|
RENDER_VERBATIM(r, " class=\"language-");
|
||||||
|
render_attribute(r, &det->lang, render_html_escaped);
|
||||||
|
RENDER_VERBATIM(r, "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
RENDER_VERBATIM(r, ">");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_open_td_block(MD_HTML* r, const MD_CHAR* cell_type, const MD_BLOCK_TD_DETAIL* det)
|
||||||
|
{
|
||||||
|
RENDER_VERBATIM(r, "<");
|
||||||
|
RENDER_VERBATIM(r, cell_type);
|
||||||
|
|
||||||
|
switch(det->align) {
|
||||||
|
case MD_ALIGN_LEFT: RENDER_VERBATIM(r, " align=\"left\">"); break;
|
||||||
|
case MD_ALIGN_CENTER: RENDER_VERBATIM(r, " align=\"center\">"); break;
|
||||||
|
case MD_ALIGN_RIGHT: RENDER_VERBATIM(r, " align=\"right\">"); break;
|
||||||
|
default: RENDER_VERBATIM(r, ">"); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_open_a_span(MD_HTML* r, const MD_SPAN_A_DETAIL* det)
|
||||||
|
{
|
||||||
|
RENDER_VERBATIM(r, "<a href=\"");
|
||||||
|
render_attribute(r, &det->href, render_url_escaped);
|
||||||
|
|
||||||
|
if(det->title.text != NULL) {
|
||||||
|
RENDER_VERBATIM(r, "\" title=\"");
|
||||||
|
render_attribute(r, &det->title, render_html_escaped);
|
||||||
|
}
|
||||||
|
|
||||||
|
RENDER_VERBATIM(r, "\">");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_open_img_span(MD_HTML* r, const MD_SPAN_IMG_DETAIL* det)
|
||||||
|
{
|
||||||
|
RENDER_VERBATIM(r, "<img src=\"");
|
||||||
|
render_attribute(r, &det->src, render_url_escaped);
|
||||||
|
|
||||||
|
RENDER_VERBATIM(r, "\" alt=\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_close_img_span(MD_HTML* r, const MD_SPAN_IMG_DETAIL* det)
|
||||||
|
{
|
||||||
|
if(det->title.text != NULL) {
|
||||||
|
RENDER_VERBATIM(r, "\" title=\"");
|
||||||
|
render_attribute(r, &det->title, render_html_escaped);
|
||||||
|
}
|
||||||
|
|
||||||
|
RENDER_VERBATIM(r, (r->flags & MD_HTML_FLAG_XHTML) ? "\" />" : "\">");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_open_wikilink_span(MD_HTML* r, const MD_SPAN_WIKILINK_DETAIL* det)
|
||||||
|
{
|
||||||
|
RENDER_VERBATIM(r, "<x-wikilink data-target=\"");
|
||||||
|
render_attribute(r, &det->target, render_html_escaped);
|
||||||
|
|
||||||
|
RENDER_VERBATIM(r, "\">");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************
|
||||||
|
*** HTML renderer implementation ***
|
||||||
|
**************************************/
|
||||||
|
|
||||||
|
static int
|
||||||
|
enter_block_callback(MD_BLOCKTYPE type, void* detail, void* userdata)
|
||||||
|
{
|
||||||
|
static const MD_CHAR* head[6] = { "<h1>", "<h2>", "<h3>", "<h4>", "<h5>", "<h6>" };
|
||||||
|
MD_HTML* r = (MD_HTML*) userdata;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case MD_BLOCK_DOC: /* noop */ break;
|
||||||
|
case MD_BLOCK_QUOTE: RENDER_VERBATIM(r, "<blockquote>\n"); break;
|
||||||
|
case MD_BLOCK_UL: RENDER_VERBATIM(r, "<ul>\n"); break;
|
||||||
|
case MD_BLOCK_OL: render_open_ol_block(r, (const MD_BLOCK_OL_DETAIL*)detail); break;
|
||||||
|
case MD_BLOCK_LI: render_open_li_block(r, (const MD_BLOCK_LI_DETAIL*)detail); break;
|
||||||
|
case MD_BLOCK_HR: RENDER_VERBATIM(r, (r->flags & MD_HTML_FLAG_XHTML) ? "<hr />\n" : "<hr>\n"); break;
|
||||||
|
case MD_BLOCK_H: RENDER_VERBATIM(r, head[((MD_BLOCK_H_DETAIL*)detail)->level - 1]); break;
|
||||||
|
case MD_BLOCK_CODE: render_open_code_block(r, (const MD_BLOCK_CODE_DETAIL*) detail); break;
|
||||||
|
case MD_BLOCK_HTML: /* noop */ break;
|
||||||
|
case MD_BLOCK_P: RENDER_VERBATIM(r, "<p>"); break;
|
||||||
|
case MD_BLOCK_TABLE: RENDER_VERBATIM(r, "<table>\n"); break;
|
||||||
|
case MD_BLOCK_THEAD: RENDER_VERBATIM(r, "<thead>\n"); break;
|
||||||
|
case MD_BLOCK_TBODY: RENDER_VERBATIM(r, "<tbody>\n"); break;
|
||||||
|
case MD_BLOCK_TR: RENDER_VERBATIM(r, "<tr>\n"); break;
|
||||||
|
case MD_BLOCK_TH: render_open_td_block(r, "th", (MD_BLOCK_TD_DETAIL*)detail); break;
|
||||||
|
case MD_BLOCK_TD: render_open_td_block(r, "td", (MD_BLOCK_TD_DETAIL*)detail); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
leave_block_callback(MD_BLOCKTYPE type, void* detail, void* userdata)
|
||||||
|
{
|
||||||
|
static const MD_CHAR* head[6] = { "</h1>\n", "</h2>\n", "</h3>\n", "</h4>\n", "</h5>\n", "</h6>\n" };
|
||||||
|
MD_HTML* r = (MD_HTML*) userdata;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case MD_BLOCK_DOC: /*noop*/ break;
|
||||||
|
case MD_BLOCK_QUOTE: RENDER_VERBATIM(r, "</blockquote>\n"); break;
|
||||||
|
case MD_BLOCK_UL: RENDER_VERBATIM(r, "</ul>\n"); break;
|
||||||
|
case MD_BLOCK_OL: RENDER_VERBATIM(r, "</ol>\n"); break;
|
||||||
|
case MD_BLOCK_LI: RENDER_VERBATIM(r, "</li>\n"); break;
|
||||||
|
case MD_BLOCK_HR: /*noop*/ break;
|
||||||
|
case MD_BLOCK_H: RENDER_VERBATIM(r, head[((MD_BLOCK_H_DETAIL*)detail)->level - 1]); break;
|
||||||
|
case MD_BLOCK_CODE: RENDER_VERBATIM(r, "</code></pre>\n"); break;
|
||||||
|
case MD_BLOCK_HTML: /* noop */ break;
|
||||||
|
case MD_BLOCK_P: RENDER_VERBATIM(r, "</p>\n"); break;
|
||||||
|
case MD_BLOCK_TABLE: RENDER_VERBATIM(r, "</table>\n"); break;
|
||||||
|
case MD_BLOCK_THEAD: RENDER_VERBATIM(r, "</thead>\n"); break;
|
||||||
|
case MD_BLOCK_TBODY: RENDER_VERBATIM(r, "</tbody>\n"); break;
|
||||||
|
case MD_BLOCK_TR: RENDER_VERBATIM(r, "</tr>\n"); break;
|
||||||
|
case MD_BLOCK_TH: RENDER_VERBATIM(r, "</th>\n"); break;
|
||||||
|
case MD_BLOCK_TD: RENDER_VERBATIM(r, "</td>\n"); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
enter_span_callback(MD_SPANTYPE type, void* detail, void* userdata)
|
||||||
|
{
|
||||||
|
MD_HTML* r = (MD_HTML*) userdata;
|
||||||
|
int inside_img = (r->image_nesting_level > 0);
|
||||||
|
|
||||||
|
/* We are inside a Markdown image label. Markdown allows to use any emphasis
|
||||||
|
* and other rich contents in that context similarly as in any link label.
|
||||||
|
*
|
||||||
|
* However, unlike in the case of links (where that contents becomescontents
|
||||||
|
* of the <a>...</a> tag), in the case of images the contents is supposed to
|
||||||
|
* fall into the attribute alt: <img alt="...">.
|
||||||
|
*
|
||||||
|
* In that context we naturally cannot output nested HTML tags. So lets
|
||||||
|
* suppress them and only output the plain text (i.e. what falls into text()
|
||||||
|
* callback).
|
||||||
|
*
|
||||||
|
* CommonMark specification declares this a recommended practice for HTML
|
||||||
|
* output.
|
||||||
|
*/
|
||||||
|
if(type == MD_SPAN_IMG)
|
||||||
|
r->image_nesting_level++;
|
||||||
|
if(inside_img)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case MD_SPAN_EM: RENDER_VERBATIM(r, "<em>"); break;
|
||||||
|
case MD_SPAN_STRONG: RENDER_VERBATIM(r, "<strong>"); break;
|
||||||
|
case MD_SPAN_U: RENDER_VERBATIM(r, "<u>"); break;
|
||||||
|
case MD_SPAN_A: render_open_a_span(r, (MD_SPAN_A_DETAIL*) detail); break;
|
||||||
|
case MD_SPAN_IMG: render_open_img_span(r, (MD_SPAN_IMG_DETAIL*) detail); break;
|
||||||
|
case MD_SPAN_CODE: RENDER_VERBATIM(r, "<code>"); break;
|
||||||
|
case MD_SPAN_DEL: RENDER_VERBATIM(r, "<del>"); break;
|
||||||
|
case MD_SPAN_LATEXMATH: RENDER_VERBATIM(r, "<x-equation>"); break;
|
||||||
|
case MD_SPAN_LATEXMATH_DISPLAY: RENDER_VERBATIM(r, "<x-equation type=\"display\">"); break;
|
||||||
|
case MD_SPAN_WIKILINK: render_open_wikilink_span(r, (MD_SPAN_WIKILINK_DETAIL*) detail); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
leave_span_callback(MD_SPANTYPE type, void* detail, void* userdata)
|
||||||
|
{
|
||||||
|
MD_HTML* r = (MD_HTML*) userdata;
|
||||||
|
|
||||||
|
if(type == MD_SPAN_IMG)
|
||||||
|
r->image_nesting_level--;
|
||||||
|
if(r->image_nesting_level > 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case MD_SPAN_EM: RENDER_VERBATIM(r, "</em>"); break;
|
||||||
|
case MD_SPAN_STRONG: RENDER_VERBATIM(r, "</strong>"); break;
|
||||||
|
case MD_SPAN_U: RENDER_VERBATIM(r, "</u>"); break;
|
||||||
|
case MD_SPAN_A: RENDER_VERBATIM(r, "</a>"); break;
|
||||||
|
case MD_SPAN_IMG: render_close_img_span(r, (MD_SPAN_IMG_DETAIL*) detail); break;
|
||||||
|
case MD_SPAN_CODE: RENDER_VERBATIM(r, "</code>"); break;
|
||||||
|
case MD_SPAN_DEL: RENDER_VERBATIM(r, "</del>"); break;
|
||||||
|
case MD_SPAN_LATEXMATH: /*fall through*/
|
||||||
|
case MD_SPAN_LATEXMATH_DISPLAY: RENDER_VERBATIM(r, "</x-equation>"); break;
|
||||||
|
case MD_SPAN_WIKILINK: RENDER_VERBATIM(r, "</x-wikilink>"); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
text_callback(MD_TEXTTYPE type, const MD_CHAR* text, MD_SIZE size, void* userdata)
|
||||||
|
{
|
||||||
|
MD_HTML* r = (MD_HTML*) userdata;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case MD_TEXT_NULLCHAR: render_utf8_codepoint(r, 0x0000, render_verbatim); break;
|
||||||
|
case MD_TEXT_BR: RENDER_VERBATIM(r, (r->image_nesting_level == 0
|
||||||
|
? ((r->flags & MD_HTML_FLAG_XHTML) ? "<br />\n" : "<br>\n")
|
||||||
|
: " "));
|
||||||
|
break;
|
||||||
|
case MD_TEXT_SOFTBR: RENDER_VERBATIM(r, (r->image_nesting_level == 0 ? "\n" : " ")); break;
|
||||||
|
case MD_TEXT_HTML: render_verbatim(r, text, size); break;
|
||||||
|
case MD_TEXT_ENTITY: render_entity(r, text, size, render_html_escaped); break;
|
||||||
|
default: render_html_escaped(r, text, size); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
debug_log_callback(const char* msg, void* userdata)
|
||||||
|
{
|
||||||
|
MD_HTML* r = (MD_HTML*) userdata;
|
||||||
|
if(r->flags & MD_HTML_FLAG_DEBUG)
|
||||||
|
fprintf(stderr, "MD4C: %s\n", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
md_html(const MD_CHAR* input, MD_SIZE input_size,
|
||||||
|
void (*process_output)(const MD_CHAR*, MD_SIZE, void*),
|
||||||
|
void* userdata, unsigned parser_flags, unsigned renderer_flags)
|
||||||
|
{
|
||||||
|
MD_HTML render = { process_output, userdata, renderer_flags, 0, { 0 } };
|
||||||
|
int i;
|
||||||
|
|
||||||
|
MD_PARSER parser = {
|
||||||
|
0,
|
||||||
|
parser_flags,
|
||||||
|
enter_block_callback,
|
||||||
|
leave_block_callback,
|
||||||
|
enter_span_callback,
|
||||||
|
leave_span_callback,
|
||||||
|
text_callback,
|
||||||
|
debug_log_callback,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Build map of characters which need escaping. */
|
||||||
|
for(i = 0; i < 256; i++) {
|
||||||
|
unsigned char ch = (unsigned char) i;
|
||||||
|
|
||||||
|
if(strchr("\"&<>", ch) != NULL)
|
||||||
|
render.escape_map[i] |= NEED_HTML_ESC_FLAG;
|
||||||
|
|
||||||
|
if(!ISALNUM(ch) && strchr("~-_.+!*(),%#@?=;:/,+$", ch) == NULL)
|
||||||
|
render.escape_map[i] |= NEED_URL_ESC_FLAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Consider skipping UTF-8 byte order mark (BOM). */
|
||||||
|
if(renderer_flags & MD_HTML_FLAG_SKIP_UTF8_BOM && sizeof(MD_CHAR) == 1) {
|
||||||
|
static const MD_CHAR bom[3] = { (char)0xef, (char)0xbb, (char)0xbf };
|
||||||
|
if(input_size >= sizeof(bom) && memcmp(input, bom, sizeof(bom)) == 0) {
|
||||||
|
input += sizeof(bom);
|
||||||
|
input_size -= sizeof(bom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return md_parse(input, input_size, &parser, (void*) &render);
|
||||||
|
}
|
||||||
|
|
||||||
68
deps_src/md4c/src/md4c-html.h
Normal file
68
deps_src/md4c/src/md4c-html.h
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* MD4C: Markdown parser for C
|
||||||
|
* (http://github.com/mity/md4c)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016-2024 Martin Mitáš
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MD4C_HTML_H
|
||||||
|
#define MD4C_HTML_H
|
||||||
|
|
||||||
|
#include "md4c.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* If set, debug output from md_parse() is sent to stderr. */
|
||||||
|
#define MD_HTML_FLAG_DEBUG 0x0001
|
||||||
|
#define MD_HTML_FLAG_VERBATIM_ENTITIES 0x0002
|
||||||
|
#define MD_HTML_FLAG_SKIP_UTF8_BOM 0x0004
|
||||||
|
#define MD_HTML_FLAG_XHTML 0x0008
|
||||||
|
|
||||||
|
|
||||||
|
/* Render Markdown into HTML.
|
||||||
|
*
|
||||||
|
* Note only contents of <body> tag is generated. Caller must generate
|
||||||
|
* HTML header/footer manually before/after calling md_html().
|
||||||
|
*
|
||||||
|
* Params input and input_size specify the Markdown input.
|
||||||
|
* Callback process_output() gets called with chunks of HTML output.
|
||||||
|
* (Typical implementation may just output the bytes to a file or append to
|
||||||
|
* some buffer).
|
||||||
|
* Param userdata is just propagated back to process_output() callback.
|
||||||
|
* Param parser_flags are flags from md4c.h propagated to md_parse().
|
||||||
|
* Param render_flags is bitmask of MD_HTML_FLAG_xxxx.
|
||||||
|
*
|
||||||
|
* Returns -1 on error (if md_parse() fails.)
|
||||||
|
* Returns 0 on success.
|
||||||
|
*/
|
||||||
|
int md_html(const MD_CHAR* input, MD_SIZE input_size,
|
||||||
|
void (*process_output)(const MD_CHAR*, MD_SIZE, void*),
|
||||||
|
void* userdata, unsigned parser_flags, unsigned renderer_flags);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" { */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* MD4C_HTML_H */
|
||||||
13
deps_src/md4c/src/md4c-html.pc.in
Normal file
13
deps_src/md4c/src/md4c-html.pc.in
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
|
exec_prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
|
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||||
|
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||||
|
|
||||||
|
Name: @PROJECT_NAME@ HTML renderer
|
||||||
|
Description: Markdown to HTML converter library.
|
||||||
|
Version: @PROJECT_VERSION@
|
||||||
|
URL: @PROJECT_URL@
|
||||||
|
|
||||||
|
Requires: md4c = @PROJECT_VERSION@
|
||||||
|
Libs: -L${libdir} -lmd4c-html
|
||||||
|
Cflags: -I${includedir}
|
||||||
6492
deps_src/md4c/src/md4c.c
Normal file
6492
deps_src/md4c/src/md4c.c
Normal file
File diff suppressed because it is too large
Load Diff
407
deps_src/md4c/src/md4c.h
Normal file
407
deps_src/md4c/src/md4c.h
Normal file
@@ -0,0 +1,407 @@
|
|||||||
|
/*
|
||||||
|
* MD4C: Markdown parser for C
|
||||||
|
* (http://github.com/mity/md4c)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016-2024 Martin Mitáš
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MD4C_H
|
||||||
|
#define MD4C_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined MD4C_USE_UTF16
|
||||||
|
/* Magic to support UTF-16. Note that in order to use it, you have to define
|
||||||
|
* the macro MD4C_USE_UTF16 both when building MD4C as well as when
|
||||||
|
* including this header in your code. */
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
typedef WCHAR MD_CHAR;
|
||||||
|
#else
|
||||||
|
#error MD4C_USE_UTF16 is only supported on Windows.
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
typedef char MD_CHAR;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef unsigned MD_SIZE;
|
||||||
|
typedef unsigned MD_OFFSET;
|
||||||
|
|
||||||
|
|
||||||
|
/* Block represents a part of document hierarchy structure like a paragraph
|
||||||
|
* or list item.
|
||||||
|
*/
|
||||||
|
typedef enum MD_BLOCKTYPE {
|
||||||
|
/* <body>...</body> */
|
||||||
|
MD_BLOCK_DOC = 0,
|
||||||
|
|
||||||
|
/* <blockquote>...</blockquote> */
|
||||||
|
MD_BLOCK_QUOTE,
|
||||||
|
|
||||||
|
/* <ul>...</ul>
|
||||||
|
* Detail: Structure MD_BLOCK_UL_DETAIL. */
|
||||||
|
MD_BLOCK_UL,
|
||||||
|
|
||||||
|
/* <ol>...</ol>
|
||||||
|
* Detail: Structure MD_BLOCK_OL_DETAIL. */
|
||||||
|
MD_BLOCK_OL,
|
||||||
|
|
||||||
|
/* <li>...</li>
|
||||||
|
* Detail: Structure MD_BLOCK_LI_DETAIL. */
|
||||||
|
MD_BLOCK_LI,
|
||||||
|
|
||||||
|
/* <hr> */
|
||||||
|
MD_BLOCK_HR,
|
||||||
|
|
||||||
|
/* <h1>...</h1> (for levels up to 6)
|
||||||
|
* Detail: Structure MD_BLOCK_H_DETAIL. */
|
||||||
|
MD_BLOCK_H,
|
||||||
|
|
||||||
|
/* <pre><code>...</code></pre>
|
||||||
|
* Note the text lines within code blocks are terminated with '\n'
|
||||||
|
* instead of explicit MD_TEXT_BR. */
|
||||||
|
MD_BLOCK_CODE,
|
||||||
|
|
||||||
|
/* Raw HTML block. This itself does not correspond to any particular HTML
|
||||||
|
* tag. The contents of it _is_ raw HTML source intended to be put
|
||||||
|
* in verbatim form to the HTML output. */
|
||||||
|
MD_BLOCK_HTML,
|
||||||
|
|
||||||
|
/* <p>...</p> */
|
||||||
|
MD_BLOCK_P,
|
||||||
|
|
||||||
|
/* <table>...</table> and its contents.
|
||||||
|
* Detail: Structure MD_BLOCK_TABLE_DETAIL (for MD_BLOCK_TABLE),
|
||||||
|
* structure MD_BLOCK_TD_DETAIL (for MD_BLOCK_TH and MD_BLOCK_TD)
|
||||||
|
* Note all of these are used only if extension MD_FLAG_TABLES is enabled. */
|
||||||
|
MD_BLOCK_TABLE,
|
||||||
|
MD_BLOCK_THEAD,
|
||||||
|
MD_BLOCK_TBODY,
|
||||||
|
MD_BLOCK_TR,
|
||||||
|
MD_BLOCK_TH,
|
||||||
|
MD_BLOCK_TD
|
||||||
|
} MD_BLOCKTYPE;
|
||||||
|
|
||||||
|
/* Span represents an in-line piece of a document which should be rendered with
|
||||||
|
* the same font, color and other attributes. A sequence of spans forms a block
|
||||||
|
* like paragraph or list item. */
|
||||||
|
typedef enum MD_SPANTYPE {
|
||||||
|
/* <em>...</em> */
|
||||||
|
MD_SPAN_EM,
|
||||||
|
|
||||||
|
/* <strong>...</strong> */
|
||||||
|
MD_SPAN_STRONG,
|
||||||
|
|
||||||
|
/* <a href="xxx">...</a>
|
||||||
|
* Detail: Structure MD_SPAN_A_DETAIL. */
|
||||||
|
MD_SPAN_A,
|
||||||
|
|
||||||
|
/* <img src="xxx">...</a>
|
||||||
|
* Detail: Structure MD_SPAN_IMG_DETAIL.
|
||||||
|
* Note: Image text can contain nested spans and even nested images.
|
||||||
|
* If rendered into ALT attribute of HTML <IMG> tag, it's responsibility
|
||||||
|
* of the parser to deal with it.
|
||||||
|
*/
|
||||||
|
MD_SPAN_IMG,
|
||||||
|
|
||||||
|
/* <code>...</code> */
|
||||||
|
MD_SPAN_CODE,
|
||||||
|
|
||||||
|
/* <del>...</del>
|
||||||
|
* Note: Recognized only when MD_FLAG_STRIKETHROUGH is enabled.
|
||||||
|
*/
|
||||||
|
MD_SPAN_DEL,
|
||||||
|
|
||||||
|
/* For recognizing inline ($) and display ($$) equations
|
||||||
|
* Note: Recognized only when MD_FLAG_LATEXMATHSPANS is enabled.
|
||||||
|
*/
|
||||||
|
MD_SPAN_LATEXMATH,
|
||||||
|
MD_SPAN_LATEXMATH_DISPLAY,
|
||||||
|
|
||||||
|
/* Wiki links
|
||||||
|
* Note: Recognized only when MD_FLAG_WIKILINKS is enabled.
|
||||||
|
*/
|
||||||
|
MD_SPAN_WIKILINK,
|
||||||
|
|
||||||
|
/* <u>...</u>
|
||||||
|
* Note: Recognized only when MD_FLAG_UNDERLINE is enabled. */
|
||||||
|
MD_SPAN_U
|
||||||
|
} MD_SPANTYPE;
|
||||||
|
|
||||||
|
/* Text is the actual textual contents of span. */
|
||||||
|
typedef enum MD_TEXTTYPE {
|
||||||
|
/* Normal text. */
|
||||||
|
MD_TEXT_NORMAL = 0,
|
||||||
|
|
||||||
|
/* NULL character. CommonMark requires replacing NULL character with
|
||||||
|
* the replacement char U+FFFD, so this allows caller to do that easily. */
|
||||||
|
MD_TEXT_NULLCHAR,
|
||||||
|
|
||||||
|
/* Line breaks.
|
||||||
|
* Note these are not sent from blocks with verbatim output (MD_BLOCK_CODE
|
||||||
|
* or MD_BLOCK_HTML). In such cases, '\n' is part of the text itself. */
|
||||||
|
MD_TEXT_BR, /* <br> (hard break) */
|
||||||
|
MD_TEXT_SOFTBR, /* '\n' in source text where it is not semantically meaningful (soft break) */
|
||||||
|
|
||||||
|
/* Entity.
|
||||||
|
* (a) Named entity, e.g.
|
||||||
|
* (Note MD4C does not have a list of known entities.
|
||||||
|
* Anything matching the regexp /&[A-Za-z][A-Za-z0-9]{1,47};/ is
|
||||||
|
* treated as a named entity.)
|
||||||
|
* (b) Numerical entity, e.g. Ӓ
|
||||||
|
* (c) Hexadecimal entity, e.g. ካ
|
||||||
|
*
|
||||||
|
* As MD4C is mostly encoding agnostic, application gets the verbatim
|
||||||
|
* entity text into the MD_PARSER::text_callback(). */
|
||||||
|
MD_TEXT_ENTITY,
|
||||||
|
|
||||||
|
/* Text in a code block (inside MD_BLOCK_CODE) or inlined code (`code`).
|
||||||
|
* If it is inside MD_BLOCK_CODE, it includes spaces for indentation and
|
||||||
|
* '\n' for new lines. MD_TEXT_BR and MD_TEXT_SOFTBR are not sent for this
|
||||||
|
* kind of text. */
|
||||||
|
MD_TEXT_CODE,
|
||||||
|
|
||||||
|
/* Text is a raw HTML. If it is contents of a raw HTML block (i.e. not
|
||||||
|
* an inline raw HTML), then MD_TEXT_BR and MD_TEXT_SOFTBR are not used.
|
||||||
|
* The text contains verbatim '\n' for the new lines. */
|
||||||
|
MD_TEXT_HTML,
|
||||||
|
|
||||||
|
/* Text is inside an equation. This is processed the same way as inlined code
|
||||||
|
* spans (`code`). */
|
||||||
|
MD_TEXT_LATEXMATH
|
||||||
|
} MD_TEXTTYPE;
|
||||||
|
|
||||||
|
|
||||||
|
/* Alignment enumeration. */
|
||||||
|
typedef enum MD_ALIGN {
|
||||||
|
MD_ALIGN_DEFAULT = 0, /* When unspecified. */
|
||||||
|
MD_ALIGN_LEFT,
|
||||||
|
MD_ALIGN_CENTER,
|
||||||
|
MD_ALIGN_RIGHT
|
||||||
|
} MD_ALIGN;
|
||||||
|
|
||||||
|
|
||||||
|
/* String attribute.
|
||||||
|
*
|
||||||
|
* This wraps strings which are outside of a normal text flow and which are
|
||||||
|
* propagated within various detailed structures, but which still may contain
|
||||||
|
* string portions of different types like e.g. entities.
|
||||||
|
*
|
||||||
|
* So, for example, lets consider this image:
|
||||||
|
*
|
||||||
|
* 
|
||||||
|
*
|
||||||
|
* The image alt text is propagated as a normal text via the MD_PARSER::text()
|
||||||
|
* callback. However, the image title ('foo " bar') is propagated as
|
||||||
|
* MD_ATTRIBUTE in MD_SPAN_IMG_DETAIL::title.
|
||||||
|
*
|
||||||
|
* Then the attribute MD_SPAN_IMG_DETAIL::title shall provide the following:
|
||||||
|
* -- [0]: "foo " (substr_types[0] == MD_TEXT_NORMAL; substr_offsets[0] == 0)
|
||||||
|
* -- [1]: """ (substr_types[1] == MD_TEXT_ENTITY; substr_offsets[1] == 4)
|
||||||
|
* -- [2]: " bar" (substr_types[2] == MD_TEXT_NORMAL; substr_offsets[2] == 10)
|
||||||
|
* -- [3]: (n/a) (n/a ; substr_offsets[3] == 14)
|
||||||
|
*
|
||||||
|
* Note that these invariants are always guaranteed:
|
||||||
|
* -- substr_offsets[0] == 0
|
||||||
|
* -- substr_offsets[LAST+1] == size
|
||||||
|
* -- Currently, only MD_TEXT_NORMAL, MD_TEXT_ENTITY, MD_TEXT_NULLCHAR
|
||||||
|
* substrings can appear. This could change only of the specification
|
||||||
|
* changes.
|
||||||
|
*/
|
||||||
|
typedef struct MD_ATTRIBUTE {
|
||||||
|
const MD_CHAR* text;
|
||||||
|
MD_SIZE size;
|
||||||
|
const MD_TEXTTYPE* substr_types;
|
||||||
|
const MD_OFFSET* substr_offsets;
|
||||||
|
} MD_ATTRIBUTE;
|
||||||
|
|
||||||
|
|
||||||
|
/* Detailed info for MD_BLOCK_UL. */
|
||||||
|
typedef struct MD_BLOCK_UL_DETAIL {
|
||||||
|
int is_tight; /* Non-zero if tight list, zero if loose. */
|
||||||
|
MD_CHAR mark; /* Item bullet character in MarkDown source of the list, e.g. '-', '+', '*'. */
|
||||||
|
} MD_BLOCK_UL_DETAIL;
|
||||||
|
|
||||||
|
/* Detailed info for MD_BLOCK_OL. */
|
||||||
|
typedef struct MD_BLOCK_OL_DETAIL {
|
||||||
|
unsigned start; /* Start index of the ordered list. */
|
||||||
|
int is_tight; /* Non-zero if tight list, zero if loose. */
|
||||||
|
MD_CHAR mark_delimiter; /* Character delimiting the item marks in MarkDown source, e.g. '.' or ')' */
|
||||||
|
} MD_BLOCK_OL_DETAIL;
|
||||||
|
|
||||||
|
/* Detailed info for MD_BLOCK_LI. */
|
||||||
|
typedef struct MD_BLOCK_LI_DETAIL {
|
||||||
|
int is_task; /* Can be non-zero only with MD_FLAG_TASKLISTS */
|
||||||
|
MD_CHAR task_mark; /* If is_task, then one of 'x', 'X' or ' '. Undefined otherwise. */
|
||||||
|
MD_OFFSET task_mark_offset; /* If is_task, then offset in the input of the char between '[' and ']'. */
|
||||||
|
} MD_BLOCK_LI_DETAIL;
|
||||||
|
|
||||||
|
/* Detailed info for MD_BLOCK_H. */
|
||||||
|
typedef struct MD_BLOCK_H_DETAIL {
|
||||||
|
unsigned level; /* Header level (1 - 6) */
|
||||||
|
} MD_BLOCK_H_DETAIL;
|
||||||
|
|
||||||
|
/* Detailed info for MD_BLOCK_CODE. */
|
||||||
|
typedef struct MD_BLOCK_CODE_DETAIL {
|
||||||
|
MD_ATTRIBUTE info;
|
||||||
|
MD_ATTRIBUTE lang;
|
||||||
|
MD_CHAR fence_char; /* The character used for fenced code block; or zero for indented code block. */
|
||||||
|
} MD_BLOCK_CODE_DETAIL;
|
||||||
|
|
||||||
|
/* Detailed info for MD_BLOCK_TABLE. */
|
||||||
|
typedef struct MD_BLOCK_TABLE_DETAIL {
|
||||||
|
unsigned col_count; /* Count of columns in the table. */
|
||||||
|
unsigned head_row_count; /* Count of rows in the table header (currently always 1) */
|
||||||
|
unsigned body_row_count; /* Count of rows in the table body */
|
||||||
|
} MD_BLOCK_TABLE_DETAIL;
|
||||||
|
|
||||||
|
/* Detailed info for MD_BLOCK_TH and MD_BLOCK_TD. */
|
||||||
|
typedef struct MD_BLOCK_TD_DETAIL {
|
||||||
|
MD_ALIGN align;
|
||||||
|
} MD_BLOCK_TD_DETAIL;
|
||||||
|
|
||||||
|
/* Detailed info for MD_SPAN_A. */
|
||||||
|
typedef struct MD_SPAN_A_DETAIL {
|
||||||
|
MD_ATTRIBUTE href;
|
||||||
|
MD_ATTRIBUTE title;
|
||||||
|
int is_autolink; /* nonzero if this is an autolink */
|
||||||
|
} MD_SPAN_A_DETAIL;
|
||||||
|
|
||||||
|
/* Detailed info for MD_SPAN_IMG. */
|
||||||
|
typedef struct MD_SPAN_IMG_DETAIL {
|
||||||
|
MD_ATTRIBUTE src;
|
||||||
|
MD_ATTRIBUTE title;
|
||||||
|
} MD_SPAN_IMG_DETAIL;
|
||||||
|
|
||||||
|
/* Detailed info for MD_SPAN_WIKILINK. */
|
||||||
|
typedef struct MD_SPAN_WIKILINK {
|
||||||
|
MD_ATTRIBUTE target;
|
||||||
|
} MD_SPAN_WIKILINK_DETAIL;
|
||||||
|
|
||||||
|
/* Flags specifying extensions/deviations from CommonMark specification.
|
||||||
|
*
|
||||||
|
* By default (when MD_PARSER::flags == 0), we follow CommonMark specification.
|
||||||
|
* The following flags may allow some extensions or deviations from it.
|
||||||
|
*/
|
||||||
|
#define MD_FLAG_COLLAPSEWHITESPACE 0x0001 /* In MD_TEXT_NORMAL, collapse non-trivial whitespace into single ' ' */
|
||||||
|
#define MD_FLAG_PERMISSIVEATXHEADERS 0x0002 /* Do not require space in ATX headers ( ###header ) */
|
||||||
|
#define MD_FLAG_PERMISSIVEURLAUTOLINKS 0x0004 /* Recognize URLs as autolinks even without '<', '>' */
|
||||||
|
#define MD_FLAG_PERMISSIVEEMAILAUTOLINKS 0x0008 /* Recognize e-mails as autolinks even without '<', '>' and 'mailto:' */
|
||||||
|
#define MD_FLAG_NOINDENTEDCODEBLOCKS 0x0010 /* Disable indented code blocks. (Only fenced code works.) */
|
||||||
|
#define MD_FLAG_NOHTMLBLOCKS 0x0020 /* Disable raw HTML blocks. */
|
||||||
|
#define MD_FLAG_NOHTMLSPANS 0x0040 /* Disable raw HTML (inline). */
|
||||||
|
#define MD_FLAG_TABLES 0x0100 /* Enable tables extension. */
|
||||||
|
#define MD_FLAG_STRIKETHROUGH 0x0200 /* Enable strikethrough extension. */
|
||||||
|
#define MD_FLAG_PERMISSIVEWWWAUTOLINKS 0x0400 /* Enable WWW autolinks (even without any scheme prefix, if they begin with 'www.') */
|
||||||
|
#define MD_FLAG_TASKLISTS 0x0800 /* Enable task list extension. */
|
||||||
|
#define MD_FLAG_LATEXMATHSPANS 0x1000 /* Enable $ and $$ containing LaTeX equations. */
|
||||||
|
#define MD_FLAG_WIKILINKS 0x2000 /* Enable wiki links extension. */
|
||||||
|
#define MD_FLAG_UNDERLINE 0x4000 /* Enable underline extension (and disables '_' for normal emphasis). */
|
||||||
|
#define MD_FLAG_HARD_SOFT_BREAKS 0x8000 /* Force all soft breaks to act as hard breaks. */
|
||||||
|
|
||||||
|
#define MD_FLAG_PERMISSIVEAUTOLINKS (MD_FLAG_PERMISSIVEEMAILAUTOLINKS | MD_FLAG_PERMISSIVEURLAUTOLINKS | MD_FLAG_PERMISSIVEWWWAUTOLINKS)
|
||||||
|
#define MD_FLAG_NOHTML (MD_FLAG_NOHTMLBLOCKS | MD_FLAG_NOHTMLSPANS)
|
||||||
|
|
||||||
|
/* Convenient sets of flags corresponding to well-known Markdown dialects.
|
||||||
|
*
|
||||||
|
* Note we may only support subset of features of the referred dialect.
|
||||||
|
* The constant just enables those extensions which bring us as close as
|
||||||
|
* possible given what features we implement.
|
||||||
|
*
|
||||||
|
* ABI compatibility note: Meaning of these can change in time as new
|
||||||
|
* extensions, bringing the dialect closer to the original, are implemented.
|
||||||
|
*/
|
||||||
|
#define MD_DIALECT_COMMONMARK 0
|
||||||
|
#define MD_DIALECT_GITHUB (MD_FLAG_PERMISSIVEAUTOLINKS | MD_FLAG_TABLES | MD_FLAG_STRIKETHROUGH | MD_FLAG_TASKLISTS)
|
||||||
|
|
||||||
|
/* Parser structure.
|
||||||
|
*/
|
||||||
|
typedef struct MD_PARSER {
|
||||||
|
/* Reserved. Set to zero.
|
||||||
|
*/
|
||||||
|
unsigned abi_version;
|
||||||
|
|
||||||
|
/* Dialect options. Bitmask of MD_FLAG_xxxx values.
|
||||||
|
*/
|
||||||
|
unsigned flags;
|
||||||
|
|
||||||
|
/* Caller-provided rendering callbacks.
|
||||||
|
*
|
||||||
|
* For some block/span types, more detailed information is provided in a
|
||||||
|
* type-specific structure pointed by the argument 'detail'.
|
||||||
|
*
|
||||||
|
* The last argument of all callbacks, 'userdata', is just propagated from
|
||||||
|
* md_parse() and is available for any use by the application.
|
||||||
|
*
|
||||||
|
* Note any strings provided to the callbacks as their arguments or as
|
||||||
|
* members of any detail structure are generally not zero-terminated.
|
||||||
|
* Application has to take the respective size information into account.
|
||||||
|
*
|
||||||
|
* Any rendering callback may abort further parsing of the document by
|
||||||
|
* returning non-zero.
|
||||||
|
*/
|
||||||
|
int (*enter_block)(MD_BLOCKTYPE /*type*/, void* /*detail*/, void* /*userdata*/);
|
||||||
|
int (*leave_block)(MD_BLOCKTYPE /*type*/, void* /*detail*/, void* /*userdata*/);
|
||||||
|
|
||||||
|
int (*enter_span)(MD_SPANTYPE /*type*/, void* /*detail*/, void* /*userdata*/);
|
||||||
|
int (*leave_span)(MD_SPANTYPE /*type*/, void* /*detail*/, void* /*userdata*/);
|
||||||
|
|
||||||
|
int (*text)(MD_TEXTTYPE /*type*/, const MD_CHAR* /*text*/, MD_SIZE /*size*/, void* /*userdata*/);
|
||||||
|
|
||||||
|
/* Debug callback. Optional (may be NULL).
|
||||||
|
*
|
||||||
|
* If provided and something goes wrong, this function gets called.
|
||||||
|
* This is intended for debugging and problem diagnosis for developers;
|
||||||
|
* it is not intended to provide any errors suitable for displaying to an
|
||||||
|
* end user.
|
||||||
|
*/
|
||||||
|
void (*debug_log)(const char* /*msg*/, void* /*userdata*/);
|
||||||
|
|
||||||
|
/* Reserved. Set to NULL.
|
||||||
|
*/
|
||||||
|
void (*syntax)(void);
|
||||||
|
} MD_PARSER;
|
||||||
|
|
||||||
|
|
||||||
|
/* For backward compatibility. Do not use in new code.
|
||||||
|
*/
|
||||||
|
typedef MD_PARSER MD_RENDERER;
|
||||||
|
|
||||||
|
|
||||||
|
/* Parse the Markdown document stored in the string 'text' of size 'size'.
|
||||||
|
* The parser provides callbacks to be called during the parsing so the
|
||||||
|
* caller can render the document on the screen or convert the Markdown
|
||||||
|
* to another format.
|
||||||
|
*
|
||||||
|
* Zero is returned on success. If a runtime error occurs (e.g. a memory
|
||||||
|
* fails), -1 is returned. If the processing is aborted due any callback
|
||||||
|
* returning non-zero, the return value of the callback is returned.
|
||||||
|
*/
|
||||||
|
int md_parse(const MD_CHAR* text, MD_SIZE size, const MD_PARSER* parser, void* userdata);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" { */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* MD4C_H */
|
||||||
13
deps_src/md4c/src/md4c.pc.in
Normal file
13
deps_src/md4c/src/md4c.pc.in
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
|
exec_prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
|
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||||
|
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||||
|
|
||||||
|
Name: @PROJECT_NAME@
|
||||||
|
Description: Markdown parser library with a SAX-like callback-based interface.
|
||||||
|
Version: @PROJECT_VERSION@
|
||||||
|
URL: @PROJECT_URL@
|
||||||
|
|
||||||
|
Requires:
|
||||||
|
Libs: -L${libdir} -lmd4c
|
||||||
|
Cflags: -I${includedir}
|
||||||
@@ -736,7 +736,7 @@ else()
|
|||||||
set(_opengl_link_lib OpenGL::GL)
|
set(_opengl_link_lib OpenGL::GL)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(libslic3r_gui libslic3r cereal::cereal imgui imguizmo minilzo libvgcode GLEW::GLEW OpenGL::GL hidapi ${wxWidgets_LIBRARIES} glfw libcurl OpenSSL::SSL OpenSSL::Crypto noise::noise)
|
target_link_libraries(libslic3r_gui libslic3r cereal::cereal imgui imguizmo minilzo libvgcode md4c-html GLEW::GLEW OpenGL::GL hidapi ${wxWidgets_LIBRARIES} glfw libcurl OpenSSL::SSL OpenSSL::Crypto noise::noise)
|
||||||
|
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
|
|||||||
@@ -5423,7 +5423,7 @@ void GUI_App::check_new_version_sf(bool show_tips, int by_user)
|
|||||||
}
|
}
|
||||||
|
|
||||||
version_info.url = prefer_release ? best_release_url : best_pre_url;
|
version_info.url = prefer_release ? best_release_url : best_pre_url;
|
||||||
version_info.version_str = prefer_release ? best_release.to_string_sf() : best_pre.to_string();
|
version_info.version_str = prefer_release ? best_release.to_string_sf() : best_pre.to_string_sf();
|
||||||
version_info.description = prefer_release ? best_release_content : best_pre_content;
|
version_info.description = prefer_release ? best_release_content : best_pre_content;
|
||||||
version_info.force_upgrade = false;
|
version_info.force_upgrade = false;
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "DeviceCore/DevManager.h"
|
#include "DeviceCore/DevManager.h"
|
||||||
#include "DeviceCore/DevStorage.h"
|
#include "DeviceCore/DevStorage.h"
|
||||||
|
#include "md4c/src/md4c-html.h"
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
@@ -268,32 +269,33 @@ UpdateVersionDialog::UpdateVersionDialog(wxWindow *parent)
|
|||||||
|
|
||||||
//webview
|
//webview
|
||||||
m_vebview_release_note = CreateTipView(m_simplebook_release_note);
|
m_vebview_release_note = CreateTipView(m_simplebook_release_note);
|
||||||
m_vebview_release_note->SetBackgroundColour(wxColour(0xF8, 0xF8, 0xF8));
|
|
||||||
m_vebview_release_note->SetSize(wxSize(FromDIP(560), FromDIP(430)));
|
m_vebview_release_note->SetSize(wxSize(FromDIP(560), FromDIP(430)));
|
||||||
m_vebview_release_note->SetMinSize(wxSize(FromDIP(560), FromDIP(430)));
|
m_vebview_release_note->SetMinSize(wxSize(FromDIP(560), FromDIP(430)));
|
||||||
//m_vebview_release_note->SetMaxSize(wxSize(FromDIP(560), FromDIP(430)));
|
//m_vebview_release_note->SetMaxSize(wxSize(FromDIP(560), FromDIP(430)));
|
||||||
m_vebview_release_note->Bind(wxEVT_WEBVIEW_NAVIGATING,[=](wxWebViewEvent& event){
|
if (wxGetApp().app_config->get_bool("developer_mode"))
|
||||||
static bool load_url_first = false;
|
m_vebview_release_note->EnableAccessToDevTools();
|
||||||
if(load_url_first){
|
|
||||||
// Orca: not used in Orca Slicer
|
|
||||||
// wxLaunchDefaultBrowser(url_line);
|
|
||||||
event.Veto();
|
|
||||||
}else{
|
|
||||||
load_url_first = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
m_vebview_release_note->Bind(wxEVT_WEBVIEW_NAVIGATING,[=, count = 0](wxWebViewEvent& event) mutable {
|
||||||
|
count++;
|
||||||
|
if (count == 1) {
|
||||||
|
m_vebview_release_note->SetPage(wxString::FromUTF8(html_source), "");
|
||||||
|
} else if (count >= 3) {
|
||||||
|
// Launch the default browser for links clicked by the user
|
||||||
|
wxLaunchDefaultBrowser(event.GetURL());
|
||||||
|
event.Veto();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fs::path ph(data_dir());
|
// fs::path ph(data_dir());
|
||||||
ph /= "resources/tooltip/releasenote.html";
|
// ph /= "resources/tooltip/releasenote.html";
|
||||||
if (!fs::exists(ph)) {
|
// if (!fs::exists(ph)) {
|
||||||
ph = resources_dir();
|
// ph = resources_dir();
|
||||||
ph /= "tooltip/releasenote.html";
|
// ph /= "tooltip/releasenote.html";
|
||||||
}
|
// }
|
||||||
auto url = ph.string();
|
// auto url = ph.string();
|
||||||
std::replace(url.begin(), url.end(), '\\', '/');
|
// std::replace(url.begin(), url.end(), '\\', '/');
|
||||||
url = "file:///" + url;
|
// url = "file:///" + url;
|
||||||
m_vebview_release_note->LoadURL(from_u8(url));
|
// m_vebview_release_note->LoadURL(from_u8(url));
|
||||||
|
|
||||||
m_simplebook_release_note->AddPage(m_scrollwindows_release_note, wxEmptyString, false);
|
m_simplebook_release_note->AddPage(m_scrollwindows_release_note, wxEmptyString, false);
|
||||||
m_simplebook_release_note->AddPage(m_vebview_release_note, wxEmptyString, false);
|
m_simplebook_release_note->AddPage(m_vebview_release_note, wxEmptyString, false);
|
||||||
@@ -470,27 +472,31 @@ void UpdateVersionDialog::update_version_info(wxString release_note, wxString ve
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (use_web_link) {
|
// if (use_web_link) {
|
||||||
m_brand->Hide();
|
// m_brand->Hide();
|
||||||
m_text_up_info->Hide();
|
// m_text_up_info->Hide();
|
||||||
m_simplebook_release_note->SetSelection(1);
|
// m_simplebook_release_note->SetSelection(1);
|
||||||
m_vebview_release_note->LoadURL(from_u8(url_line));
|
// m_vebview_release_note->LoadURL(from_u8(url_line));
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
m_simplebook_release_note->SetMaxSize(wxSize(FromDIP(560), FromDIP(430)));
|
m_simplebook_release_note->SetMaxSize(wxSize(FromDIP(560), FromDIP(430)));
|
||||||
m_simplebook_release_note->SetSelection(0);
|
m_simplebook_release_note->SetSelection(1);
|
||||||
m_text_up_info->SetLabel(wxString::Format(_L("Click to download new version in default browser: %s"), version));
|
m_text_up_info->SetLabel(wxString::Format(_L("Click to download new version in default browser: %s"), version));
|
||||||
wxBoxSizer* sizer_text_release_note = new wxBoxSizer(wxVERTICAL);
|
auto data_buf_in = release_note.utf8_str();
|
||||||
auto m_staticText_release_note = new ::Label(m_scrollwindows_release_note, release_note, LB_AUTO_WRAP);
|
auto bg_color = StateColor::darkModeColorFor(*wxWHITE).GetAsString();
|
||||||
m_staticText_release_note->SetMinSize(wxSize(FromDIP(560), -1));
|
auto fg_color = StateColor::darkModeColorFor(*wxBLACK).GetAsString();
|
||||||
m_staticText_release_note->SetMaxSize(wxSize(FromDIP(560), -1));
|
html_source = (boost::format("<html><head><style>body { color: %1%; background-color: %2%; font-family: sans-serif; } a { color: #1E90FF }</style></head><body>")
|
||||||
sizer_text_release_note->Add(m_staticText_release_note, 0, wxALL, 5);
|
% fg_color % bg_color).str();
|
||||||
m_scrollwindows_release_note->SetSizer(sizer_text_release_note);
|
md_html(data_buf_in.data(), data_buf_in.length(), [](const MD_CHAR* text, MD_SIZE size, void* userdata) {
|
||||||
m_scrollwindows_release_note->Layout();
|
std::string* out_buf = (std::string*)userdata;
|
||||||
m_scrollwindows_release_note->Fit();
|
out_buf->append(text, size);
|
||||||
SetMinSize(GetSize());
|
}, (void*) &html_source, MD_DIALECT_GITHUB | MD_FLAG_STRIKETHROUGH | MD_FLAG_WIKILINKS, 0);
|
||||||
SetMaxSize(GetSize());
|
html_source.append("</body></html>");
|
||||||
}
|
m_vebview_release_note->LoadURL("file://" + (boost::filesystem::path (resources_dir()) / "web/guide/0/index.html").string());
|
||||||
|
|
||||||
|
SetMinSize(GetSize());
|
||||||
|
SetMaxSize(GetSize());
|
||||||
|
// }
|
||||||
|
|
||||||
wxGetApp().UpdateDlgDarkUI(this);
|
wxGetApp().UpdateDlgDarkUI(this);
|
||||||
Layout();
|
Layout();
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ public:
|
|||||||
Button* m_button_download;
|
Button* m_button_download;
|
||||||
Button* m_button_cancel;
|
Button* m_button_cancel;
|
||||||
std::string url_line;
|
std::string url_line;
|
||||||
|
std::string html_source;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SecondaryCheckDialog : public DPIFrame
|
class SecondaryCheckDialog : public DPIFrame
|
||||||
|
|||||||
Reference in New Issue
Block a user