Skip to content

Commit

Permalink
πŸ“š Docs: @ref links and macros
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Jul 27, 2020
1 parent ed37a43 commit 115e3de
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Pluto"
uuid = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
license = "MIT"
authors = ["Fons van der Plas <[email protected]>", "MikoΕ‚aj Bochenski <[email protected]>"]
version = "0.11.0"
version = "0.11.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
13 changes: 13 additions & 0 deletions frontend/components/CellOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,22 @@ export class RawHTMLContainer extends Component {
console.info("Failed to typeset TeX:")
console.info(err)
}

if(this.props.on_render != null){
this.props.on_render(this.base)
}
})
}

shouldComponentUpdate(new_props) {
const pure = this.props.pure === true && new_props.pure === true
if (pure) {
return this.props.body !== new_props.body
} else {
return true
}
}

componentDidUpdate() {
this.render_DOM()
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/DropRuler.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class DropRuler extends Component {
/* SELECTIONS */

document.addEventListener("mousedown", (e) => {
if (e.target.tagName === "MAIN" || e.target.tagName === "NOTEBOOK" || e.target.tagName === "PREAMBLE") {
if (e.button === 0 && (e.target.tagName === "MAIN" || e.target.tagName === "NOTEBOOK" || e.target.tagName === "PREAMBLE")) {
this.precompute_cell_edges()
const new_index = this.getDropIndexOf(e.pageY)
this.setState({
Expand Down
7 changes: 6 additions & 1 deletion frontend/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,12 @@ export class Editor extends Component {
}}
/>
</main>
<${LiveDocs} desired_doc_query=${this.state.desired_doc_query} client=${this.client} notebook=${this.state.notebook} />
<${LiveDocs}
desired_doc_query=${this.state.desired_doc_query}
on_update_doc_query=${(query) => this.setState({ desired_doc_query: query })}
client=${this.client}
notebook=${this.state.notebook}
/>
<footer>
<div id="info">
<form id="feedback" action="#" method="post">
Expand Down
20 changes: 19 additions & 1 deletion frontend/components/LiveDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,28 @@ export class LiveDocs extends Component {
</header>
<section>
<h1><code>${this.state.shown_query}</code></h1>
<${RawHTMLContainer} body=${this.state.body} />
<${RawHTMLContainer}
body=${this.state.body}
pure=${true}
on_render=${(n) => resolve_doc_reference_links(n, this.props.on_update_doc_query)}
/>
</section>
</helpbox>
</div>
`
}
}

const resolve_doc_reference_links = (node, on_update_doc_query) => {
const as = node.querySelectorAll("a")
as.forEach((a) => {
const href = a.getAttribute("href")
if (href != null && href.startsWith("@ref")) {
const query = href.length > 4 ? href.substr(5) : a.textContent
a.onclick = (e) => {
on_update_doc_query(query)
e.preventDefault()
}
}
})
}
24 changes: 17 additions & 7 deletions src/runner/PlutoRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,24 @@ function completion_fetcher(query, pos, workspace::Module=current_module)
(completion_text.(results), loc, found)
end

# Based on /base/docs/bindings.jl from Julia source code
function binding_from(x::Expr, workspace::Module=current_module)
if x.head == :macrocall
Docs.Binding(workspace, x.args[1])
elseif x.head == :.
Docs.Binding(Core.eval(workspace, x.args[1]), x.args[2])
else
error("Invalid @var syntax `$x`.")
end
end
binding_from(s::Symbol, workspace::Module=current_module) = Docs.Binding(workspace, s)
binding_from(r::GlobalRef, workspace::Module=current_module) = Docs.Binding(r.mod, r.name)
binding_from(other, workspace::Module=current_module) = error("Invalid @var syntax `$other`.")

function doc_fetcher(query, workspace::Module=current_module)
try
obj = Core.eval(workspace, Meta.parse(query))
if obj isa Expr
(nothing, :πŸ‘Ž)
else
(repr(MIME"text/html"(), Docs.doc(obj)), :πŸ‘)
end
binding = binding_from(Meta.parse(query), workspace)::Docs.Binding
(repr(MIME"text/html"(), Docs.doc(binding)), :πŸ‘)
catch ex
(nothing, :πŸ‘Ž)
end
Expand All @@ -523,7 +533,7 @@ end

"""`@bind symbol element`
Returns the HTML `element`, and uses its latest JavaScript value as the definition of `symbol`.
Return the HTML `element`, and use its latest JavaScript value as the definition of `symbol`.
# Example
Expand Down
2 changes: 1 addition & 1 deletion src/webserver/Static.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function http_router_for(session::ServerSession)
function serve_sample(req::HTTP.Request)
uri = HTTP.URI(req.target)
sample_path = HTTP.URIs.unescapeuri(split(uri.path, "sample/")[2])
sample_path_without_dotjl = sample_path[1:end - 3]
sample_path_without_dotjl = "sample " * sample_path[1:end - 3]

path = numbered_until_new(joinpath(tempdir(), sample_path_without_dotjl))
readwrite(joinpath(PKG_ROOT_DIR, "sample", sample_path), path)
Expand Down

3 comments on commit 115e3de

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 115e3de Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/18536

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.1 -m "<description of version>" 115e3deb4ad459453410d376a880495c79417e06
git push origin v0.11.1

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 115e3de Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.