-
Notifications
You must be signed in to change notification settings - Fork 393
Literate forester without external tool #8290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dannypsnl
wants to merge
17
commits into
agda:master
Choose a base branch
from
dannypsnl:literate-forester-without-external-tool
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
17dd2d6
literate agda tree no need external tool now
dannypsnl 5ad6973
forester no need HTML escape, but need lexer escape
dannypsnl b6282ea
minimal import
dannypsnl 2f7db6c
update related document
dannypsnl f9c090e
cabal format
dannypsnl b14dc1f
test: update test case
dannypsnl f64028e
literate agda document
dannypsnl 295e0f1
test TreeHighlight
dannypsnl f506fb9
test: fix module name
dannypsnl 42f6b65
add flags
dannypsnl e743294
improve first paragraph
dannypsnl b966259
improve second paragraph
dannypsnl ed194d4
improve build steps
dannypsnl c31ab90
add CHANGELOG entry
dannypsnl 87264b5
add forester config to view example
dannypsnl 475c247
use `mconcat` and `<>`
dannypsnl dbda2b4
misc format issue
dannypsnl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
src/full/Agda/Interaction/Highlighting/HTML/Forester.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| module Agda.Interaction.Highlighting.HTML.Forester | ||
| ( renderForesterHtml, | ||
| ) | ||
| where | ||
|
|
||
| import Data.ByteString (ByteString) | ||
| import Data.ByteString qualified as S (isInfixOf) | ||
| import Data.List (isInfixOf) | ||
| import Data.Monoid (mappend, mempty) | ||
| import Data.Text (Text) | ||
| import Data.Text qualified as T | ||
| import Data.Text.Encoding (decodeUtf8) | ||
| import Data.Text.Lazy qualified as L | ||
| import Data.Text.Lazy.Builder (Builder) | ||
| import Data.Text.Lazy.Builder qualified as B | ||
| import Text.Blaze.Html5 (Html) | ||
| import Text.Blaze.Internal | ||
| ( ChoiceString (..), | ||
| MarkupM (..), | ||
| StaticString (getText), | ||
| ) | ||
|
|
||
| fromChoiceString :: | ||
| -- | Decoder for bytestrings | ||
| (ByteString -> Text) -> | ||
| -- | String to render | ||
| ChoiceString -> | ||
| -- | Resulting builder | ||
| Builder | ||
| fromChoiceString _ (Static s) = B.fromText $ getText s | ||
| fromChoiceString _ (String s) = B.fromText $ T.pack s | ||
| fromChoiceString _ (Text s) = B.fromText s | ||
| fromChoiceString d (ByteString s) = B.fromText $ d s | ||
| fromChoiceString d (PreEscaped x) = case x of | ||
| String s -> B.fromText $ T.pack s | ||
| Text s -> B.fromText s | ||
| s -> fromChoiceString d s | ||
| fromChoiceString d (External x) = case x of | ||
| -- Check that the sequence "</" is *not* in the external data. | ||
| String s -> if "</" `isInfixOf` s then mempty else B.fromText (T.pack s) | ||
| Text s -> if "</" `T.isInfixOf` s then mempty else B.fromText s | ||
| ByteString s -> if "</" `S.isInfixOf` s then mempty else B.fromText (d s) | ||
| s -> fromChoiceString d s | ||
| fromChoiceString d (AppendChoiceString x y) = | ||
| fromChoiceString d x `mappend` fromChoiceString d y | ||
| fromChoiceString _ EmptyChoiceString = mempty | ||
| {-# INLINE fromChoiceString #-} | ||
dannypsnl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| modify_open :: StaticString -> Text | ||
| modify_open open = | ||
| let a = getText open | ||
| in T.cons '<' (T.append "html:" (T.tail a)) | ||
|
|
||
| modify_key :: StaticString -> Text | ||
| modify_key key = | ||
| let a = getText key | ||
| in T.dropEnd 2 (T.strip a) | ||
|
|
||
| -- Escape for forester lexer | ||
| wrap_verb :: Builder -> Builder | ||
| wrap_verb w = B.fromLazyText $ L.foldr go "" (B.toLazyText w) | ||
| where | ||
| go :: Char -> L.Text -> L.Text | ||
| go '[' acc = L.append "\\startverb[\\stopverb" acc | ||
| go ']' acc = L.append "\\startverb]\\stopverb" acc | ||
| go x acc = L.cons x acc | ||
|
|
||
| renderMarkupBuilderWith :: | ||
| (ByteString -> Text) -> | ||
| Html -> | ||
| Builder | ||
| renderMarkupBuilderWith d = go mempty | ||
| where | ||
| go :: Builder -> MarkupM b -> Builder | ||
| go attrs (Parent _ open close content) = | ||
| mconcat | ||
| [ B.fromText "\\", | ||
| B.fromText (modify_open open), | ||
| B.fromText ">", | ||
| attrs, | ||
| B.fromText "{", | ||
| go mempty content, | ||
| B.fromText "}" | ||
| ] | ||
| go attrs (CustomParent tag content) = | ||
| mconcat | ||
| [ B.fromText "\\<html:", | ||
| fromChoiceString d tag, | ||
| B.fromText ">", | ||
| attrs, | ||
| B.fromText "{", | ||
| go mempty content, | ||
| fromChoiceString d tag, | ||
| B.fromText "}" | ||
| ] | ||
| go attrs (Leaf _ begin end _) = | ||
| mconcat | ||
| [ B.fromText (modify_open begin), | ||
| B.fromText ">", | ||
| attrs, | ||
| B.fromText "{}" | ||
| ] | ||
| go attrs (CustomLeaf tag close _) = | ||
| mconcat | ||
| [ B.fromText "\\<html:", | ||
| fromChoiceString d tag, | ||
| attrs, | ||
| B.fromText ">{}" | ||
| ] | ||
| go attrs (AddAttribute _ key value h) = | ||
| go | ||
| ( mconcat | ||
| [ B.singleton '[', | ||
| B.fromText (modify_key key), | ||
| B.fromText "]{", | ||
| wrap_verb (fromChoiceString d value), | ||
| B.fromText "}", | ||
| attrs | ||
| ] | ||
| ) | ||
| h | ||
| go attrs (AddCustomAttribute key value h) = | ||
| go | ||
| ( mconcat | ||
| [ B.singleton '[', | ||
| fromChoiceString d key, | ||
| B.fromText "]{", | ||
| wrap_verb (fromChoiceString d value), | ||
| B.fromText "}", | ||
| attrs | ||
| ] | ||
| ) | ||
| h | ||
| go _ (Content content _) = wrap_verb (fromChoiceString d content) | ||
| go _ (Comment comment _) = B.fromText "% " <> fromChoiceString d comment | ||
| go attrs (Append h1 h2) = go attrs h1 <> go attrs h2 | ||
| go _ (Empty _) = mempty | ||
| {-# NOINLINE go #-} | ||
| {-# INLINE renderMarkupBuilderWith #-} | ||
|
|
||
| renderMarkupWith :: (ByteString -> Text) -> Html -> L.Text | ||
| renderMarkupWith d = B.toLazyText . renderMarkupBuilderWith d | ||
| {-# INLINE renderMarkupWith #-} | ||
|
|
||
| renderForesterHtml :: Html -> L.Text | ||
| renderForesterHtml = renderMarkupWith decodeUtf8 | ||
| {-# INLINE renderForesterHtml #-} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| html/ | ||
| output/ | ||
| theme |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| --html-highlight=code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| \title{simple} | ||
|
|
||
| \p{This is test file} | ||
| \<html:pre>[class]{Agda}{ | ||
| \<html:a>[id]{46}[class]{Keyword}{module} \<html:a>[id]{53}[href]{TreeHighlightSimple.html}[class]{Module}{TreeHighlightSimple} \<html:a>[id]{73}[class]{Keyword}{where} | ||
|
|
||
| \<html:a>[id]{82}[class]{Keyword}{data} \<html:a>[id]{Bool}{}\<html:a>[id]{87}[href]{TreeHighlightSimple.html#87}[class]{Datatype}{Bool} \<html:a>[id]{92}[class]{Symbol}{:} \<html:a>[id]{94}[href]{Agda.Primitive.html#388}[class]{Primitive}{Set} \<html:a>[id]{98}[class]{Keyword}{where} | ||
| \<html:a>[id]{Bool.true}{}\<html:a>[id]{116}[href]{TreeHighlightSimple.html#116}[class]{InductiveConstructor}{true} \<html:a>[id]{121}[class]{Symbol}{:} \<html:a>[id]{123}[href]{TreeHighlightSimple.html#87}[class]{Datatype}{Bool} | ||
| \<html:a>[id]{Bool.false}{}\<html:a>[id]{140}[href]{TreeHighlightSimple.html#140}[class]{InductiveConstructor}{false} \<html:a>[id]{146}[class]{Symbol}{:} \<html:a>[id]{148}[href]{TreeHighlightSimple.html#87}[class]{Datatype}{Bool} | ||
|
|
||
| \<html:a>[id]{a}{}\<html:a>[id]{156}[href]{TreeHighlightSimple.html#156}[class]{Function}{a} \<html:a>[id]{158}[class]{Symbol}{:} \<html:a>[id]{160}[href]{TreeHighlightSimple.html#87}[class]{Datatype}{Bool} | ||
| \<html:a>[id]{167}[href]{TreeHighlightSimple.html#156}[class]{Function}{a} \<html:a>[id]{169}[class]{Symbol}{=} \<html:a>[id]{171}[href]{TreeHighlightSimple.html#116}[class]{InductiveConstructor}{true} | ||
| } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [forest] | ||
| trees = ["trees", "html"] # The directories in which your trees are stored |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| \title{Index} | ||
|
|
||
| \p{Check [[TreeHighlightSimple]]} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.