Note, this macro requires the custom action plugin at:
For reference, unminified .js source code:
// Rob Trew, Twitter @ ComplexPoint 2015.
// ( the mdString() function includes code adapted from David Bengoa's https://gist.github.com/YouWoTMA/1762527 )
(function () {
'use strict';
function fnAttributes(strPath, strAnchor, strFormat, blnFirstOnly) {
// PATH STARTS AT DOCUMENT ROOT, OR SELECTION ?
var nodeAttribs = function (oNode) {
varType = (
oNode ?
oNode.nodeType :
null
),
varA…
Macro : click somewhere in a line of text in Safari or Chrome,
and trigger the macro to copy:
the enclosing paragraph (as Markdown)
any preceding heading
a link to the document
the date and time
Copy paragraph from web with heading, link, and date.kmmacros (22.8 KB)
2 Likes
Hey, Rob, thanks for another great macro.
May I suggest that you allow for a selection in addition to clicking somewhere?
I would find that more useful since just clicking pulls just a small portion of the text I want.
Thanks.
May not get around to it before the end of the week, but in the meanwhile, if you want to have a try:
Get the .focusNode of the selection, as well as the .anchorNode,
write an XPath expression which finds the nearest common ancestor of the two nodes, and
apply the mdString() function to that shared ancestor.
For the common ancestor XPath, see this discussion:
( PS if you don’t need Markdown, you can just evaluate .toString()
on the selection object )
sims
February 6, 2019, 1:42pm
4
@ComplexPoint First, thank you for sharing this macro. Very useful.
By any chance, did either you or @JMichaelTX , get around to making one that can also act on a selection in the browser?
I do not know Javascript, and therefore am not even able to try and figure the common ancestor suggestion that you have made here.
Please post this question as a NEW topic, and be much more specific about what you are requesting. Please provide a real-world example of the web page (including URL), and exactly what you would like the results to look like.
Also, please see:
Tip: How Do I Get The Best Answer in the Shortest Time?