Page MenuHomePhabricator

Feature to copy or download code blocks
Closed, ResolvedPublic

Assigned To
Authored By
MarkTraceur
Aug 1 2012, 9:50 PM
Referenced Files
F57537561: image.png
Wed, Sep 25, 7:55 PM
Tokens
"Doubloon" token, awarded by Volker_E."Love" token, awarded by Aschroet."Love" token, awarded by Ladsgroup."Like" token, awarded by scfc."Mountain of Wealth" token, awarded by Ricordisamoa.

Description

Original description (2012):

DokuWiki [0] has downloadable code blocks as a matter of course. It would be cool to have that in SyntaxHighlight.

My inkling is that there's very little work to do, since it would basically just be offering a link that would open a new window or so, and put in the new content (the content of the code block). I don't think there's anything complicated that needs to happen.

I'll look into this later this week maybe, but if anyone else wants to whack at it for a while, be my guest!

[0] https://www.dokuwiki.org/syntax#downloadable_code_blocks

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 12:50 AM
bzimport set Reference to bz38932.
bzimport added a subscriber: Unknown Object (MLST).

Note for later: This is for people on #octave, and the person who asked for it was [email protected] (no BZ account)

The DokuWiki link changed to https://www.dokuwiki.org/wiki:syntax#downloadable_code_blocks; for the use of Gists on blogs, cf. http://www.sandywalsh.com/2011/06/effective-units-tests-and-integration.html.

Some thoughts:

  • Some code blocks should be downloadable, some (snippets?) maybe not. I'd prefer the default to be downloadable.
  • There's always lots of drama with user-specified filenames on insecure browsers that MediaWiki fosters, so this needs to be checked.
  • Gists are saved server-side, DokuWiki seems to parse the page on every call which also means that the link may lead to updated (= different) content than shown. I haven't tried it, but data URIs should be performant, stable and supported by enough browsers.

Otherwise: Really cool! :-) In many cases, I just want to copy and paste bits of the code block, but often enough I'd like to save the lot and so far have to carefully maneuver the mouse pointer twice and then still face whitespace issues & Co.

(In reply to Tim Landscheidt from comment #2)

[...]

  • Gists are saved server-side, DokuWiki seems to parse the page on every

call which also means that the link may lead to updated (= different)
content than shown. I haven't tried it, but data URIs should be performant,
stable and supported by enough browsers.
[...]

data URIs work fine, but unfortunately do not bear a "filename", so for example Google Chrome wants to save all data URIs as "Download". So it's probably necessary to imitate Dokuwiki and parse the page again, probably cached.

Krinkle renamed this task from Downloadable code blocks (suggestion from IRC) to Feature to download code block as text file.Jan 5 2015, 1:00 PM
Krinkle updated the task description. (Show Details)
Krinkle removed a project: good first task.
Krinkle set Security to None.
Krinkle removed a subscriber: Unknown Object (MLST).

Mediawiki.org now has JS to copy code fragments. For example on https://www.mediawiki.org/wiki/Local_development_quickstart
using the gadget tpl-copy. https://www.mediawiki.org/wiki/MediaWiki:Gadget-site-tpl-copy.js

site[ResourceLoader|default|peers=site-styles|dependencies=mediawiki.util,ext.gadget.site-styles]|site.js|site-tpl-copy.js|site-tpl-copy.css

We could consider adding this into core

Change #1071940 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/SyntaxHighlight_GeSHi@master] Implement copy links for code blocks

https://gerrit.wikimedia.org/r/1071940

Change #1071940 merged by jenkins-bot:

[mediawiki/extensions/SyntaxHighlight_GeSHi@master] Implement copy buttons for code blocks

https://gerrit.wikimedia.org/r/1071940

SD0001 renamed this task from Feature to download code block as text file to Feature to copy or download code blocks.Tue, Sep 24, 5:05 PM
SD0001 closed this task as Resolved.
SD0001 claimed this task.
SD0001 updated the task description. (Show Details)

Suggested text: <syntaxhighlight> code blocks will now offer a "Copy" button if copy=1 attribute is set on the tag.

@SD0001 Hi, I was checking an example (intending to add it as a screenshot in this task's Description, for anyone who clicks thru from Tech News), and I noticed that:

  • adding copy=1 also seems to change the width of the entire block.

It doesn't seem to change any linewraps, so it might be fine (?), but it might be unexpected/unintended.
E.g. using this sandbox (edit freely) https://en.wikipedia.beta.wmflabs.org/wiki/User:Quiddity/sandbox

image.png (425×1 px, 31 KB)

[EDIT: I think it also needs documentation in https://www.mediawiki.org/wiki/Extension:SyntaxHighlight ]

Change #1075976 had a related patch set uploaded (by Ammarpad; author: Ammarpad):

[mediawiki/extensions/SyntaxHighlight_GeSHi@master] modules: Do not constraint code block with copy button

https://gerrit.wikimedia.org/r/1075976

I'll postpone announcing this for one more week, so that the above patch (thanks Ammarpad!) can be merged, and thus users won't see that bug when they test it out.

Change #1075976 merged by jenkins-bot:

[mediawiki/extensions/SyntaxHighlight_GeSHi@master] modules: Remove width limit for code block with copy button

https://gerrit.wikimedia.org/r/1075976

The added code sadly lacks night mode support even though all the colours used are from Codex/OOUI palette.

Change #1076302 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/SyntaxHighlight_GeSHi@master] copy button: use Codex colors for dark mode compatibility

https://gerrit.wikimedia.org/r/1076302

Change #1076302 merged by jenkins-bot:

[mediawiki/extensions/SyntaxHighlight_GeSHi@master] copy button: use Codex colors for dark mode compatibility

https://gerrit.wikimedia.org/r/1076302