-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from openmls/keks/highlighting-bookmarklet
Add bookmarklet page
- Loading branch information
Showing
4 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,82 @@ | ||
let Prelude = | ||
https://prelude.dhall-lang.org/v22.0.0/package.dhall | ||
sha256:1c7622fdc868fe3a23462df3e6f533e50fdc12ecf3b42c0bb45c328ec8c4293e | ||
let XML = Prelude.XML | ||
|
||
let Property | ||
: Type | ||
= { key : Text, value : Text } | ||
|
||
let Property/highlight | ||
: Property | ||
= { key = "background-color", value = "#fde995" } | ||
|
||
let Property/cssText | ||
: Property -> Text | ||
= \(prop : Property) -> prop.key ++ ":" ++ prop.value ++ ";" | ||
|
||
let PropertyList = List Property | ||
|
||
let PropertyList/cssText = | ||
\(list : PropertyList) -> | ||
Prelude.Text.concatMapSep "\n" Property Property/cssText list | ||
|
||
let IdSelector | ||
: Type | ||
= { id : Text } | ||
|
||
let IdSelector/cssText | ||
: IdSelector -> Text | ||
= \(sel : IdSelector) -> "#" ++ Prelude.Text.replace "." "\\." sel.id | ||
|
||
let IdSelectorList = List IdSelector | ||
|
||
let IdSelectorList/cssText = | ||
\(list : IdSelectorList) -> | ||
Prelude.Text.concatMapSep ",%0a" IdSelector IdSelector/cssText list | ||
|
||
let IdSelectorsRule | ||
: Type | ||
= { selectors : IdSelectorList, properties : PropertyList } | ||
|
||
let IdSelectorsRule/cssText = | ||
\(rule : IdSelectorsRule) -> | ||
let selectors = IdSelectorList/cssText rule.selectors | ||
|
||
let properties = PropertyList/cssText rule.properties | ||
|
||
in "${selectors} { ${properties} }" | ||
|
||
let IdSelectorsRule/styleBlock = | ||
\(rule : IdSelectorsRule) -> | ||
XML.element | ||
{ name = "style" | ||
, attributes = [ XML.attribute "type" "text/css" ] | ||
, content = [ XML.rawText (IdSelectorsRule/cssText rule) ] | ||
} | ||
|
||
let IdSelectorsRule/bookmarklet = | ||
\(rule : IdSelectorsRule) -> | ||
let cssText = IdSelectorsRule/cssText rule | ||
|
||
let jsBody = | ||
'' | ||
let cssBody = document.createTextNode(String.raw`${cssText}`); | ||
let styleElem = document.createElement('style'); | ||
document.head.appendChild(styleElem); | ||
styleElem.setAttribute('type', 'text/css'); | ||
styleElem.appendChild(cssBody); | ||
'' | ||
|
||
let jsWrapped = "void function(){${jsBody}}()" | ||
|
||
in "javascript:${jsWrapped}" | ||
|
||
in { Property | ||
, Property/highlight | ||
, IdSelector | ||
, IdSelectorsRule | ||
, IdSelectorsRule/cssText | ||
, IdSelectorsRule/styleBlock | ||
, IdSelectorsRule/bookmarklet | ||
} |
This file contains 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,51 @@ | ||
let Prelude = | ||
https://prelude.dhall-lang.org/v22.0.0/package.dhall | ||
sha256:1c7622fdc868fe3a23462df3e6f533e50fdc12ecf3b42c0bb45c328ec8c4293e | ||
let XML = Prelude.XML | ||
|
||
let Types = ../types.dhall | ||
|
||
let Css = ../utils/css.dhall | ||
let Html = ../utils/html.dhall | ||
|
||
let checksets = ../checksets.dhall | ||
|
||
let Check/fragments = \(check : Types.Check) -> check.desc.rfcFragments | ||
|
||
let CheckSet/fragments = | ||
\(checkSet : Types.CheckSet) -> | ||
Prelude.List.foldLeft | ||
Types.Check | ||
checkSet.checks | ||
(List Text) | ||
(\(acc : List Text) -> \(cur : Types.Check) -> acc # Check/fragments cur) | ||
([]: List Text) | ||
|
||
let fragments = Prelude.List.concatMap Types.CheckSet Text CheckSet/fragments checksets | ||
|
||
let cssSelectors = | ||
Prelude.List.map | ||
Text | ||
Css.IdSelector | ||
(\(fragment : Text) -> { id = fragment }) | ||
fragments | ||
|
||
let cssProperties = [ Css.Property/highlight ] | ||
|
||
let cssRule | ||
: Css.IdSelectorsRule | ||
= { selectors = cssSelectors, properties = cssProperties } | ||
|
||
let bookmarklet = Css.IdSelectorsRule/bookmarklet cssRule | ||
|
||
let linkElem = | ||
XML.element | ||
{ name = "a" | ||
, attributes = [ XML.attribute "href" bookmarklet ] | ||
, content = [ XML.rawText "✨ Highlight MLS RFC" ] | ||
} | ||
|
||
let label = XML.rawText "Drag this to your bookmarks bar:" | ||
|
||
let page= Html.outerTemplate "Bookmarklet page" [ label, linkElem ] | ||
in "<!DOCTYPE html>" ++ XML.render page |
This file contains 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