# How to store data in a Mma SE question using hidden html-like markup?

Mathematica Stack Exchange accepts HTML in the questions, and therefore text such as

<undefined rubbish>


should be ignored when formatting the question for display, but still be available when editing the question.

How can we take advantage of this to elegantly store data in the question that can be easily retrieved using minimal Mathematica code?

A plain text solution would be ideal.

The storage limits should be worked out.

I'm looking for a technical answer, in the hope that developing that would give more options to answer this other question in meta. A different topic is if doing this would break the rules of Mma SE, of if using this method could be advisable or not. That is to be discussed in meta, here.

• I think this should go on meta instead. You've seen the recent related question there. Apr 25 '17 at 11:41
• I thought about that, but I want to look for a technical answer that would make the code short and the use seamless. If that becomes a valid policy, should be a meta discussion. Apr 25 '17 at 11:42
• While such a feature sounds convenient I'd personally be hesitant to use it because importing and running code directly from a website is dangerous. (still +1 from me) Apr 25 '17 at 15:12
• Related: (74198). SE-Tools can also do this (SEEncodeExpression/SEDecodeImage). Apr 25 '17 at 17:27
• To be fair, anybody using the SE Uploader palette is also running Import[url1][url2] that is, executing code from url1. May 9 '17 at 12:43

## Store data in question

Tables could be left in plain text, with some encoding to remove CR and LF characters and other symbols.

EncodeForQuestion[expr_List] :=
CopyToClipboard[
URLEncode[ExportString[expr, "CSV"]], "\"/>"]]


Arbitrary data can be expressed as plain text with InputForm and ToString or compressed (Compress) into plain text and wrapped into "<>" markers

InputFormForQuestion[expr_] :=
CopyToClipboard[
URLEncode[ToString[InputForm[expr]]], "\"/>"]]

CompressForQuestion[expr_] := CopyToClipboard[
StringJoin[
, Compress[expr]
, "\"/>"]
]


and pasted at the end of the question.

This has the advantage that the display of the question is not affected, the format is obvious and can be retrieved by hand if necessary, going to edit the question to then copy&paste the data. Hopefully in the future the browser add-on could provide a link to the data to download.

## Programmatically retrieve the data

The plain text markdown version of the question body can be retrieved by using the Stack Exchange API without evaluating, for inspection.

GetQuestionPlain[SEQuestionId_Integer] := Import[
URLBuild[
{"https://api.stackexchange.com", "2.2", "posts", ToString[SEQuestionId]}
, {"site" -> "mathematica", "filter" -> "!SWK9z)LGKmEEgF5)yL"}]
, "RawJSON"][["items", 1, "body_markdown"]]


The data stored in the question can be downloaded and parsed using

GetDataFromQuestion[SEQuestionId_Integer] :=
StringCases[GetQuestionPlain[SEQuestionId],


Where GetDataFromQuestion takes as argument the question ID available in the URL.

## Example:

Uncompress/@GetDataFromQuestion[144472]


Notice that this allows multiple sets of data.

## To do

• Work out storage limits.
• Use labels to identify multiple payloads

Feel free to edit this answer.

• Trick,and Any convenient method can get that SEQuestionId?
– yode
Apr 25 '17 at 11:37
• Could I give a suggestion for that parameter can be SEQuestionId_Integer|websiteAddress?If it can accept websiteAddress,then we just need right-click that share.And I don't know why it will pop this windows when I run your code..
– yode
Apr 25 '17 at 11:42
• Does anybody else get that pop-up window? I don't get it even if logged off Wolfram. Apr 25 '17 at 12:27
• You can get the SEQuestionID by copying the Share URL and then URLParse[NotebookGet[ClipboardNotebook[]][[1, 1, 1]]][["Path", 3]] Apr 25 '17 at 15:22