From d0ea96452ef786c76ce79da752fd70130eb57dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 2 Feb 2025 10:45:41 +0100 Subject: [PATCH] epub fixes, closes #2087 --- assets/js/tooltips/tooltips.js | 2 +- .../{html-NL4GMUWY.js => html-6VTPNSGQ.js} | 2 +- lib/ex_doc/formatter/epub/templates.ex | 8 ------ .../epub/templates/nav_item_template.eex | 9 ------- .../formatter/epub/templates/nav_template.eex | 25 +++++++++++-------- .../html/templates/detail_template.eex | 2 +- .../html/templates/summary_template.eex | 2 +- test/ex_doc/formatter/epub/templates_test.exs | 2 +- test/ex_doc/formatter/html/templates_test.exs | 6 ++--- 9 files changed, 23 insertions(+), 35 deletions(-) rename formatters/html/dist/{html-NL4GMUWY.js => html-6VTPNSGQ.js} (97%) delete mode 100644 lib/ex_doc/formatter/epub/templates/nav_item_template.eex diff --git a/assets/js/tooltips/tooltips.js b/assets/js/tooltips/tooltips.js index 8bb5ef1b5..765f703b4 100644 --- a/assets/js/tooltips/tooltips.js +++ b/assets/js/tooltips/tooltips.js @@ -6,7 +6,7 @@ import tooltipBodyTemplate from '../handlebars/templates/tooltip-body.handlebars const TOOLTIP_HTML = '
' // Elements that can activate the tooltip. -const TOOLTIP_ACTIVATORS_SELECTOR = '.content a:not([data-no-tooltip])' +const TOOLTIP_ACTIVATORS_SELECTOR = '.content a:not([data-no-tooltip=""])' // Tooltip root element. const TOOLTIP_SELECTOR = '.tooltip' // Tooltip content element. diff --git a/formatters/html/dist/html-NL4GMUWY.js b/formatters/html/dist/html-6VTPNSGQ.js similarity index 97% rename from formatters/html/dist/html-NL4GMUWY.js rename to formatters/html/dist/html-6VTPNSGQ.js index 3110be1c2..634d1ba4e 100644 --- a/formatters/html/dist/html-NL4GMUWY.js +++ b/formatters/html/dist/html-6VTPNSGQ.js @@ -70,7 +70,7 @@ See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-contr `+((s=l(n,"if").call(e??(t.nullContext||{}),(s=e!=null?l(e,"hint"):e)!=null?l(s,"description"):s,{name:"if",hash:{},fn:t.program(4,i,0),inverse:t.noop,data:i,loc:{start:{line:12,column:2},end:{line:16,column:9}}}))!=null?s:"")},4:function(t,e,n,r,i){var s,o=t.lookupProperty||function(a,l){if(Object.prototype.hasOwnProperty.call(a,l))return a[l]};return`
`+((s=t.lambda((s=e!=null?o(e,"hint"):e)!=null?o(s,"description"):s,e))!=null?s:"")+`
-`},compiler:[8,">= 4.3.0"],main:function(t,e,n,r,i){var s,o=t.lookupProperty||function(a,l){if(Object.prototype.hasOwnProperty.call(a,l))return a[l]};return(s=o(n,"if").call(e??(t.nullContext||{}),e!=null?o(e,"isPlain"):e,{name:"if",hash:{},fn:t.program(1,i,0),inverse:t.program(3,i,0),data:i,loc:{start:{line:1,column:0},end:{line:17,column:7}}}))!=null?s:""},useData:!0});var ml='
',gl=".content a:not([data-no-tooltip])",yn=".tooltip",qi=".tooltip .tooltip-body",Fi="body .content-inner",vl="#content",Vi="tooltip-shown",Se=10,yl=Se*4,wl=768,bl=450,El=100,le={currentLinkElement:null,hoverDelayTimeout:null};window.addEventListener("exdoc:loaded",xl);function xl(){M(gl).forEach(t=>{kl(t)&&(t.addEventListener("mouseenter",Ll),t.addEventListener("mouseleave",_l))})}function kl(t){return!(Sl(t.href)||!Zn(t.href))}function Sl(t){let e=t.replace(vl,"");return window.location.href.split("#")[0]===e}function Ll(t){if(window.innerWidth{er(e.href).then(Tl).catch(()=>{})},El)}function Tl(t){let e=Qi({isPlain:t.kind===ie.plain,hint:t}),n=f(qi);n||(f(Fi).insertAdjacentHTML("beforeend",ml),n=f(qi)),n.innerHTML=e,Pl(),f(yn).classList.add(Vi)}function _l(){le.currentLinkElement&&(clearTimeout(le.hoverDelayTimeout),nr(),le.currentLinkElement=null,f(yn)?.classList.remove(Vi))}function Pl(){if(!le.currentLinkElement)return;let t=f(yn),e=le.currentLinkElement.getBoundingClientRect(),n=f(Fi).getBoundingClientRect(),r=t.getBoundingClientRect(),i=Ol(e,n);if(e.left+r.width+Se code:first-child):not(:has(.copy-button))").forEach(t=>{if(!wn){let r=document.createElement("div");r.innerHTML=$i,wn=r.firstChild}let e=wn.cloneNode(!0);t.appendChild(e);let n;e.addEventListener("click",()=>{clearTimeout(n);let r=Array.from(t.querySelectorAll("code > *:not(.unselectable)")).map(i=>i.textContent).join("");navigator.clipboard.writeText(r),e.classList.add("clicked"),e.disabled=!0,n=setTimeout(()=>{e.classList.remove("clicked"),e.disabled=!1},3e3)})})}var V=Y(Wi());var zi=Y(ae());var Gi=zi.template({1:function(t,e,n,r,i){var s,o=t.lookupProperty||function(a,l){if(Object.prototype.hasOwnProperty.call(a,l))return a[l]};return" Search results for "+t.escapeExpression((s=(s=o(n,"value")||(e!=null?o(e,"value"):e))!=null?s:t.hooks.helperMissing,typeof s=="function"?s.call(e??(t.nullContext||{}),{name:"value",hash:{},data:i,loc:{start:{line:3,column:27},end:{line:3,column:36}}}):s))+` +`},compiler:[8,">= 4.3.0"],main:function(t,e,n,r,i){var s,o=t.lookupProperty||function(a,l){if(Object.prototype.hasOwnProperty.call(a,l))return a[l]};return(s=o(n,"if").call(e??(t.nullContext||{}),e!=null?o(e,"isPlain"):e,{name:"if",hash:{},fn:t.program(1,i,0),inverse:t.program(3,i,0),data:i,loc:{start:{line:1,column:0},end:{line:17,column:7}}}))!=null?s:""},useData:!0});var ml='
',gl='.content a:not([data-no-tooltip=""])',yn=".tooltip",qi=".tooltip .tooltip-body",Fi="body .content-inner",vl="#content",Vi="tooltip-shown",Se=10,yl=Se*4,wl=768,bl=450,El=100,le={currentLinkElement:null,hoverDelayTimeout:null};window.addEventListener("exdoc:loaded",xl);function xl(){M(gl).forEach(t=>{kl(t)&&(t.addEventListener("mouseenter",Ll),t.addEventListener("mouseleave",_l))})}function kl(t){return!(Sl(t.href)||!Zn(t.href))}function Sl(t){let e=t.replace(vl,"");return window.location.href.split("#")[0]===e}function Ll(t){if(window.innerWidth{er(e.href).then(Tl).catch(()=>{})},El)}function Tl(t){let e=Qi({isPlain:t.kind===ie.plain,hint:t}),n=f(qi);n||(f(Fi).insertAdjacentHTML("beforeend",ml),n=f(qi)),n.innerHTML=e,Pl(),f(yn).classList.add(Vi)}function _l(){le.currentLinkElement&&(clearTimeout(le.hoverDelayTimeout),nr(),le.currentLinkElement=null,f(yn)?.classList.remove(Vi))}function Pl(){if(!le.currentLinkElement)return;let t=f(yn),e=le.currentLinkElement.getBoundingClientRect(),n=f(Fi).getBoundingClientRect(),r=t.getBoundingClientRect(),i=Ol(e,n);if(e.left+r.width+Se code:first-child):not(:has(.copy-button))").forEach(t=>{if(!wn){let r=document.createElement("div");r.innerHTML=$i,wn=r.firstChild}let e=wn.cloneNode(!0);t.appendChild(e);let n;e.addEventListener("click",()=>{clearTimeout(n);let r=Array.from(t.querySelectorAll("code > *:not(.unselectable)")).map(i=>i.textContent).join("");navigator.clipboard.writeText(r),e.classList.add("clicked"),e.disabled=!0,n=setTimeout(()=>{e.classList.remove("clicked"),e.disabled=!1},3e3)})})}var V=Y(Wi());var zi=Y(ae());var Gi=zi.template({1:function(t,e,n,r,i){var s,o=t.lookupProperty||function(a,l){if(Object.prototype.hasOwnProperty.call(a,l))return a[l]};return" Search results for "+t.escapeExpression((s=(s=o(n,"value")||(e!=null?o(e,"value"):e))!=null?s:t.hooks.helperMissing,typeof s=="function"?s.call(e??(t.nullContext||{}),{name:"value",hash:{},data:i,loc:{start:{line:3,column:27},end:{line:3,column:36}}}):s))+` `},3:function(t,e,n,r,i){return` Invalid search `},5:function(t,e,n,r,i){var s,o=t.lookupProperty||function(a,l){if(Object.prototype.hasOwnProperty.call(a,l))return a[l]};return(s=o(n,"each").call(e??(t.nullContext||{}),e!=null?o(e,"results"):e,{name:"each",hash:{},fn:t.program(6,i,0),inverse:t.noop,data:i,loc:{start:{line:10,column:2},end:{line:21,column:11}}}))!=null?s:""},6:function(t,e,n,r,i){var s,o=t.lambda,a=t.escapeExpression,l=t.lookupProperty||function(u,c){if(Object.prototype.hasOwnProperty.call(u,c))return u[c]};return`

diff --git a/lib/ex_doc/formatter/epub/templates.ex b/lib/ex_doc/formatter/epub/templates.ex index 4a822c7f2..9e4e72f3b 100644 --- a/lib/ex_doc/formatter/epub/templates.ex +++ b/lib/ex_doc/formatter/epub/templates.ex @@ -99,14 +99,6 @@ defmodule ExDoc.Formatter.EPUB.Templates do trim: true ) - EEx.function_from_file( - :defp, - :nav_item_template, - Path.expand("templates/nav_item_template.eex", __DIR__), - [:name, :nodes], - trim: true - ) - EEx.function_from_file( :defp, :nav_grouped_item_template, diff --git a/lib/ex_doc/formatter/epub/templates/nav_item_template.eex b/lib/ex_doc/formatter/epub/templates/nav_item_template.eex deleted file mode 100644 index aaf4ab584..000000000 --- a/lib/ex_doc/formatter/epub/templates/nav_item_template.eex +++ /dev/null @@ -1,9 +0,0 @@ -<%= unless Enum.empty?(nodes) do %> -
  • <%= name %> -
      - <%= for node <- nodes do %> -
    1. <%=h node.title %>
    2. - <% end %> -
    -
  • -<% end %> diff --git a/lib/ex_doc/formatter/epub/templates/nav_template.eex b/lib/ex_doc/formatter/epub/templates/nav_template.eex index 935e40a44..e5a54021e 100644 --- a/lib/ex_doc/formatter/epub/templates/nav_template.eex +++ b/lib/ex_doc/formatter/epub/templates/nav_template.eex @@ -2,20 +2,25 @@

    Table of contents

    <%= before_closing_body_tag(config, :epub) %> diff --git a/lib/ex_doc/formatter/html/templates/detail_template.eex b/lib/ex_doc/formatter/html/templates/detail_template.eex index 89459e886..3b5ec916e 100644 --- a/lib/ex_doc/formatter/html/templates/detail_template.eex +++ b/lib/ex_doc/formatter/html/templates/detail_template.eex @@ -3,7 +3,7 @@ "> <% end %>
    - +
    diff --git a/lib/ex_doc/formatter/html/templates/summary_template.eex b/lib/ex_doc/formatter/html/templates/summary_template.eex index 90fcd3569..b01667050 100644 --- a/lib/ex_doc/formatter/html/templates/summary_template.eex +++ b/lib/ex_doc/formatter/html/templates/summary_template.eex @@ -5,7 +5,7 @@ <%= for node <- nodes do %>
    - <%=h node.signature %> + <%=h node.signature %> <%= if deprecated = node.deprecated do %> deprecated <% end %> diff --git a/test/ex_doc/formatter/epub/templates_test.exs b/test/ex_doc/formatter/epub/templates_test.exs index 5b4836800..d69281807 100644 --- a/test/ex_doc/formatter/epub/templates_test.exs +++ b/test/ex_doc/formatter/epub/templates_test.exs @@ -145,7 +145,7 @@ defmodule ExDoc.Formatter.EPUB.TemplatesTest do content = get_module_page([CompiledWithDocs]) assert content =~ - ~r{
    \s*} + ~r{
    \s*} end test "contains links to summary sections when those exist" do diff --git a/test/ex_doc/formatter/html/templates_test.exs b/test/ex_doc/formatter/html/templates_test.exs index 2eaa56409..0e8c27947 100644 --- a/test/ex_doc/formatter/html/templates_test.exs +++ b/test/ex_doc/formatter/html/templates_test.exs @@ -478,7 +478,7 @@ defmodule ExDoc.Formatter.HTML.TemplatesTest do assert content =~ ~s{example(foo, bar \\\\ Baz)} assert content =~ - ~r{\s*\s*}ms + ~r{\s*\s*}ms end test "outputs function groups", context do @@ -519,7 +519,7 @@ defmodule ExDoc.Formatter.HTML.TemplatesTest do ~S[TypesAndSpecs.Sub.t(), ] <> ~S[opaque(), :ok | :error}] - assert content =~ ~s[public(t)] + assert content =~ ~s[public(t)] refute content =~ ~s[private] assert content =~ public_html refute content =~ ~s[private\(t\)] @@ -538,7 +538,7 @@ defmodule ExDoc.Formatter.HTML.TemplatesTest do content = get_module_page([CompiledWithDocs], context) assert content =~ - ~r{