Skip to content

Commit

Permalink
add sig special case for conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyvetter committed Feb 21, 2018
1 parent f020c3b commit 7d6e998
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/extension/common/localDom.re
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Element = {
[@bs.get] external id : t => string = "id";
[@bs.set] external setId : (t, string) => unit = "id";
[@bs.set] external setInnerHTML : (t, string) => unit = "innerHTML";
[@bs.get] external outerHTML : t => string = "outerHTML";
[@bs.get] external innerText : t => string = "innerText";
[@bs.set] external setInnerText : (t, string) => unit = "innerText";
[@bs.set] external setTitle : (t, string) => unit = "title";
Expand Down
31 changes: 28 additions & 3 deletions src/extension/content/convert/retrieve.re
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,36 @@ let getTypeTable = (pre) =>
}
};

let getModuleSignature = (pre) =>
switch (Js.String.endsWith("sig .. end", Element.innerText(pre))) {
| false => None
| true =>
let anchor = LocalDom.Arrayish.toArray(
Element.getElementsByTagName(pre, "a")
)[0];
let anchor = Element.outerHTML(anchor);
let re = [%re "/sig .. end/g"];
let replaced = Js.String.unsafeReplaceBy0(
re,
(_, _, _) => "{ " ++ anchor ++ " }",
Element.innerText(pre)
);
Some({
els: [pre],
text: "",
replace: (_html) => {
Element.setInnerHTML(pre, replaced);
pre
}
})
};

let getPreListings = () =>
getElementsByTagName(None, "pre")
|> List.map(
(el) =>
switch (getTypeTable(el)) {
| Some(typeTable) => {
switch (getTypeTable(el), getModuleSignature(el)) {
| (Some(typeTable), _) => {
els: [el, typeTable.el],
text: Element.innerText(el) ++ typeTable.text,
replace: (html) => {
Expand All @@ -55,7 +79,8 @@ let getPreListings = () =>
el
}
}
| None => {
| (_, Some(preListing)) => preListing
| (None, None) => {
els: [el],
text: Element.innerText(el),
replace: (html) => {
Expand Down

0 comments on commit 7d6e998

Please sign in to comment.