Commit Graph

90 Commits

Author SHA1 Message Date
Timothy Flynn
b5f22b6e90 AK+Userland: Remove some needlessly explicit conversions to StringView 2024-04-04 11:23:21 +02:00
Shannon Booth
e2e7c4d574 Everywhere: Use to_number<T> instead of to_{int,uint,float,double}
In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
2023-12-23 20:41:07 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Gurkirat Singh
da8a3f9ff2 LibMarkdown: Render slugified anchor tag in heading
Because slugify function accepts AK::String, which can hold unicode
code_points as well, heading text is normalised to ensure with NFD
form to ensure same binary respresentation of a particular string.
2023-10-30 10:39:59 +00:00
Ali Caglayan
1ee3ec16a9 Userland: Fix absolute paths in man page links
Absolute paths in man page links such as

```
[some link](/foo/bar)
```

Were being interpreted as relative paths when rendered in HTML. This
issue was observed in #20889 and #20041.

The fix is to make sure we don't leave any absolute paths when parsing
links. Instead we check if a directory is absolute (by checking for `/`)
and add `file://` accordingly. This turns the above link into:

```
[some link](file:///foo/bar)
```

Which does get interpreted correctly when rendered as HTML.

- fixes #20889
- fixes #20041

Before this patch, opening the Help application would raise an error.
Now all the pictures in the man pages render correctly.
2023-09-06 15:02:44 +01:00
Ali Mohammad Pur
ba4db899d4 LibSyntax+Userland: Make LibSyntax not depend on LibGUI
This moves some stuff around to make LibGUI depend on LibSyntax instead
of the other way around, as not every application that wishes to do
syntax highlighting is necessarily a LibGUI (or even a GUI) application.
2023-08-29 07:57:39 -04:00
Liav A
22737b70bc LibMarkdown: Add render_for_raw_print methods to Node derived classes
This method will be used by the package manager code to render an actual
Port's name to raw text as it is stored as relative URL currently in the
AvailablePorts.md file.
2023-08-07 13:24:25 -06:00
Liav A
8073c615af LibMarkdown: Add method to get access to Table columns
This will be used later when parsing the AvailablePorts.md file in the
upcoming package manager application.
2023-08-07 13:24:25 -06:00
ronak69
bed5a752df LibMarkdown: Preserve blank lines in CodeBlocks
Specifically, `CodeBlock::render_lines_for_terminal()` eats up blank
lines because it uses `DeprecatedString::split()` without the
`SplitBehavior::KeepEmpty` enum. Easy fix: use the enum.
2023-08-04 13:16:32 +02:00
Carwyn Nelson
e44abaa777 LibMarkdown: Convert render_to_terminal to String
This commit converts render_to_terminal from DeprecatedString to return
an ErrorOr<String>. This is to aid moving `man` away from
DeprecatedString.

I have opted not to convert render_to_html and render_to_inline_html for
now to keep this commit as small as possible.
2023-07-03 02:05:32 +02:00
Maciej
cf52542fcf LibMarkdown+LibSyntax: Add a Markdown syntax highlighter
It currently supports only headers and code blocks.
2023-05-05 17:08:40 +01:00
Maciej
416d6ab6c8 LibMarkdown: Make LineIterator::operator- take a const reference 2023-05-05 17:08:40 +01:00
Tim Ledbetter
bebcf71bdc LibMarkdown: Avoid catastrophic backtracking in thematic break regex
Fixes #17937
2023-04-14 16:02:59 +01:00
Andreas Kling
21db2b7b90 Everywhere: Remove NonnullOwnPtr.h includes 2023-03-06 23:46:35 +01:00
Andreas Kling
359d6e7b0b Everywhere: Stop using NonnullOwnPtrVector
Same as NonnullRefPtrVector: weird semantics, questionable benefits.
2023-03-06 23:46:35 +01:00
Linus Groh
6e7459322d AK: Remove StringBuilder::build() in favor of to_deprecated_string()
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00
Ben Wiederhake
6fd478b6ce Everywhere: Remove unused includes of AK/Format.h
These instances were detected by searching for files that include
AK/Format.h, but don't match the regex:

\\b(CheckedFormatString|critical_dmesgln|dbgln|dbgln_if|dmesgln|FormatBu
ilder|__FormatIfSupported|FormatIfSupported|FormatParser|FormatString|Fo
rmattable|Formatter|__format_value|HasFormatter|max_format_arguments|out
|outln|set_debug_enabled|StandardFormatter|TypeErasedFormatParams|TypeEr
asedParameter|VariadicFormatParams|v_critical_dmesgln|vdbgln|vdmesgln|vf
ormat|vout|warn|warnln|warnln_if)\\b

(Without the linebreaks.)

This regex is pessimistic, so there might be more files that don't
actually use any formatting functions.

Observe that this revealed that Userland/Libraries/LibC/signal.cpp is
missing an include.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:27:20 -05:00
Ben Wiederhake
8a331d4fa0 Everywhere: Move AK/Debug.h include to using files or remove 2023-01-02 20:27:20 -05:00
Arda Cinar
c9d434247d LibMarkdown: Indent blockquotes inside the terminal renderer
This removes one FIXME :^)
2022-12-31 00:09:23 +01:00
Arda Cinar
5cc984d74c LibMarkdown: Render lines to terminal instead of a single string
With this patch, the blocks in a markdown document render a vector of
lines. These lines get concatenated in Document::render_to_terminal, so
this does not change any external APIs of LibMarkdown.

This change makes it possible to indent individual lines in the rendered
markdown. So, rendering blockquotes in a similar way to code blocks :^)
2022-12-31 00:09:23 +01:00
Arda Cinar
e2566d5126 LibMarkdown: Prevent a crash when rendering code blocks to console
When parsing a code block not in a section (in a file without a
heading), the parser would initialize the code block with an
uninitialized (invalid) value for current_section. Accessing this value
would later cause a segmentation fault in render_to_terminal.
2022-12-15 16:30:21 +00:00
Arda Cinar
80563120e2 LibMarkdown: Handle error while rendering JS to HTML
The library logs the error and falls back to not colorizing the js code
inside the block instead.
2022-12-15 16:30:21 +00:00
Linus Groh
112b3f7342 LibJS: Convert MarkupGenerator to the new String 2022-12-07 09:58:38 +00:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Nico Weber
daeaefad17 Everywhere: Clean up "the the" comment typos 2022-11-03 17:38:32 +00:00
Tim Schumacher
ce2f1b845f Everywhere: Mark dependencies of most targets as PRIVATE
Otherwise, we end up propagating those dependencies into targets that
link against that library, which creates unnecessary link-time
dependencies.

Also included are changes to readd now missing dependencies to tools
that actually need them.
2022-11-01 14:49:09 +00:00
demostanis
3e8b5ac920 AK+Everywhere: Turn bool keep_empty to an enum in split* functions 2022-10-24 23:29:18 +01:00
Sam Atkins
aea4fbdd7b LibMarkdown: Allow extra content to be inserted into HTML output's head
This lets users supply custom styling and scripting, among other things.
2022-09-28 23:58:26 +01:00
demostanis
68c6161f25 LibMarkdown: Add newline and remove ANSI escape after code blocks
Also make clang-tidy happy by making line a const&
2022-09-01 23:36:23 +00:00
demostanis
1ce23eb640 LibMarkdown: Fix coloring of the first line
The escape sequence to color a section's name was separated
by a newline from the section's name, making less(1) trim
the escape sequence off when the section's name was on the
first line.
2022-08-04 16:57:26 +00:00
demostanis
55b7f8ab27 LibMarkdown: Indent code blocks 2022-08-04 16:57:26 +00:00
MacDue
8140b1fa18 LibMarkdown: Implement the image size extension
This implements the image size extension that's quite commonly used:
https://github.com/commonmark/commonmark-spec/wiki/Deployed-Extensions#image-size

This supports specifying...

Both width and height: ![](foo.png =100x200)
Width only: ![](foo.png =100x)
Height only: ![](foo.png =x200)

The size is always in pixels (relative sizing does not seem
to be spec'd anywhere).
2022-08-04 02:49:29 +02:00
sin-ack
c8585b77d2 Everywhere: Replace single-char StringView op. arguments with chars
This prevents us from needing a sv suffix, and potentially reduces the
need to run generic code for a single character (as contains,
starts_with, ends_with etc. for a char will be just a length and
equality check).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
huttongrabiel
25970f2763 LibMarkdown: Add strike-through text support to markdown
Using ~~text~~ syntax will strike out the text between the two tildes.

Only missing portion is the terminal rendering of strike through text.
The ansi escape codes for strike through text are \e[9m and \e[29m but
it appears the terminal does not support these. Please correct me if I
am wrong.

I tested that the render_to_terminal function was being called by giving
it bold ANSI escape codes, and that did work so the function is being
called correctly.
2022-04-28 22:15:08 +02:00
huttongrabiel
1e65e916fc LibMarkdown: Correct typo in forward declaration of HorizontalRule
HoriziontalRule -> HorizontalRule
2022-04-26 23:23:36 -07:00
Peter Elliott
5847d326c3 LibMarkdown: Treat whitespace-only lines as blank in paragraphs 2022-04-26 15:02:26 +02:00
Peter Elliott
aef5aac772 LibMarkdown: Don't put a newline in empty code blocks
This doesn't actually matter, but I'm trying to match the commonmark
test cases where possible.
2022-04-26 15:02:26 +02:00
Peter Elliott
e084e1ced6 LibMarkdown: Better support for code fences
- Support tildes.
- Support different lengths of fence.
- Begrudgingly keep support for serenities one markdown extension.
2022-04-26 15:02:26 +02:00
Peter Elliott
4d3454d700 LibMarkdown: Support up to 3 spaces before an ATX header 2022-04-26 15:02:26 +02:00
Peter Elliott
116e0dc4de LibMarkdown: Limit headings to 6 levels 2022-04-26 15:02:26 +02:00
Peter Elliott
c15c57a6af LibMarkdown: Make thematic break parsing more correct
also fix a conflict with lists and thematic breaks
2022-04-26 15:02:26 +02:00
Peter Elliott
5ad44ac2e5 LibMarkdown: Ignore backslash on non-punctuation characters 2022-04-26 15:02:26 +02:00
Peter Elliott
0270e23997 LibMarkdown: Add support for indented code blocks 2022-04-26 15:02:26 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Lenny Maiorani
dd08e84664 Libraries: Use default constructors/destructors in LibMarkdown
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-13 22:34:38 +01:00
xSlendiX
7685d53654 LibMarkdown: Add terminal color formatting
This patch adds color formatting to markdown viewed in the terminal.
This also increases readability.
2022-02-17 19:54:47 +01:00
xSlendiX
5d219ad4f7 LibMarkdown: Add additional spacing for terminal rendering
This patch adds spacing to give a sense of structure to markdown
documents viewed in the terminal. This also makes the content easier
to read.
2022-02-17 19:54:47 +01:00
mjz19910
10ec98dd38 Everywhere: Fix spelling mistakes 2022-01-07 15:44:42 +01:00