Skip to content

Commit

Permalink
fix(markdown): change syntax highlight API to take an option(string) …
Browse files Browse the repository at this point in the history
…for language (revery-ui#917)

* Markdown: change syntax highlight API to take option(string) for language

* Formatting

* Get rid of merge conflicts :)

* format,

* Don't switch on label

* Drop wildcard for None

Co-authored-by: Glenn Slotte <glenn@slotte.net>

Co-authored-by: Github Runner <runner@runner.github.com>
Co-authored-by: Glenn Slotte <glenn@slotte.net>
  • Loading branch information
3 people authored Jun 22, 2020
1 parent f3f2e9b commit 464c5b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
21 changes: 5 additions & 16 deletions src/UI_Components/Markdown.re
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ module SyntaxHighlight = {
bold: bool,
italic: bool,
}
and t = (~language: string, list(string)) => list(list(highlight));
and t =
(~language: option(string), list(string)) => list(list(highlight));

let makeHighlight = (~byteIndex, ~color, ~bold, ~italic): highlight => {
byteIndex,
Expand Down Expand Up @@ -407,20 +408,8 @@ and generateCodeBlock =
);

<View style={styles.codeBlock}>
{switch (label, codeBlock.code) {
| (None, Some(code)) =>
<Text
text=code
fontFamily={styles.codeFontFamily}
monospaced=true
fontSize={styles.codeBlockFontSize}
style=Style.[
textWrap(TextWrapping.WrapIgnoreWhitespace),
...{styles.paragraph},
]
/>

| (Some(label), Some(code)) =>
{switch (codeBlock.code) {
| Some(code) =>
let lines = String.split_on_char('\n', code);
let highlights = highlighter(~language=label, lines);
List.map2(
Expand Down Expand Up @@ -460,7 +449,7 @@ and generateCodeBlock =
)
|> React.listToElement;

| (_, _) => <View />
| None => <View />
}}
</View>;
};
Expand Down
3 changes: 2 additions & 1 deletion src/UI_Components/Markdown.rei
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module SyntaxHighlight: {
type highlight;
type t = (~language: string, list(string)) => list(list(highlight));
type t =
(~language: option(string), list(string)) => list(list(highlight));

let default: t;

Expand Down

0 comments on commit 464c5b7

Please sign in to comment.