Git Product home page Git Product logo

m2md's People

Contributors

kubapod avatar nhannht avatar robertolupi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

m2md's Issues

Smart conversion with respect to whitespaces

{StyleBox["x ", FontWeight -> Bold], "=", "1"}

Currently it strictly becomes

**x **=1

Which will not be rendered well.

A similar issue is when a hyperlink is not followed by a whitespace. It will be rendered verbatim rather than a real hyperlink.

The agreement is to make a smart conversion that will spare users this headaches. By default it should be enabled.

ASCII operators

Not all operators / special characters have ASCII counterparts that will be parsed back to WL correctly. Convert only those which will (-> etc).

Incorrect export of images in TraditionalForm

TraditionalForm output cells may also contain images. Currently, this is not accounted
for in

M2MD[style_, cell:_[BoxData @ FormBox[_, TraditionalForm], ___], OptionsPattern[]
] := MDElement["LaTeXBlock", BoxesToTeXString @ cell ];

Changing the function

M2MD[style_, cell:_[BoxData @ FormBox[_, TraditionalForm], ___], OptionsPattern[]
] := MDElement["LaTeXBlock", BoxesToTeXString @ cell ]/;!inlineImageQ[cell];

seems to fix the issue. Here is an example of a misbehaving cell

Cell[BoxData[
 FormBox[
  GraphicsBox[{InsetBox[
     GraphicsBox[
      TagBox[
       TooltipBox[
        {Thickness[0.005], 
         LineBox[{{-5.4569682106375694`*^-12, 15.000000000005457`}, {5.999999999996362, 
          10.000000000001819`}}], 
         PolygonBox[{{3.4609327677584254`, 12.115889360201312`}, {2.2829934723757828`, 
          12.576822127959739`}, {2.7951409921073664`, 13.191399151637638`}}], InsetBox[
          TagBox[
           StyleBox[
            TagBox["e",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->29.323636363636364`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            29.323636363636364`]& ], {2.6125141805200567, 11.914057016624067}, {1, 1}], 
         LineBox[{{-9.094947017729282*^-12, 4.999999999992724}, {5.999999999994543, 
          9.999999999994543}}], 
         PolygonBox[{{2.5390672322415746`, 7.1158893602013125`}, {3.7170065276242172`, 
          7.576822127959737}, {3.2048590078926336`, 8.191399151637638}}], InsetBox[
          TagBox[
           StyleBox[
            TagBox["e",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->29.323636363636364`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            29.323636363636364`]& ], {3.387485819479944, 6.914057016624067}, {-1, 1}], 
         LineBox[{{20.000000000007276`, 15.000000000003638`}, {14.000000000005457`, 
          10.000000000003638`}}], 
         PolygonBox[{{17.460932767758425`, 12.884110639798688`}, {16.282993472375782`, 
          12.423177872040261`}, {16.795140992107367`, 11.808600848362362`}}], InsetBox[
          TagBox[
           StyleBox[
            TagBox["e",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->29.323636363636364`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            29.323636363636364`]& ], {16.61251418052006, 13.085942983375933}, {1, -1}], 
         LineBox[{{20.00000000000182, 5.000000000001819}, {14., 10.}}], 
         PolygonBox[{{16.539067232241575`, 7.8841106397986875`}, {17.717006527624218`, 
          7.423177872040263}, {17.204859007892633`, 6.808600848362362}}], InsetBox[
          TagBox[
           StyleBox[
            TagBox["e",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->29.323636363636364`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            29.323636363636364`]& ], {17.38748581947994, 8.085942983375933}, {-1, -1}], 
         LineBox[CompressedData["
1:eJxFlH9QVFUUx98CbTFkM00yICzL7t4bCyKzbrcknaRjTQI22IozsSM1sNA+
QCcxoVQSsEiymQgx2PYZCSbpgn+QQCYzMq4SC8htQWAa/FVGghAw7qhTQcl2
6I/bm3nz5jP3vXfvOef7/epzCtPtAZI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j
jxT+PWO7/4yiRAp/q1vMu9awSOH/vlld2QiPEPlw7YOhiUI5QuTHE/3rXgyR
IkS+1NJA+EZZIfInOUjqXc9WiHxSh98YH+XhIr+Kdp4a3i6Hi3y7P7qkvzCR
f/8CUmEAYA==
          "]], InsetBox[
          TagBox[
           StyleBox[
            TagBox["\[Gamma]",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->29.323636363636364`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            29.323636363636364`]& ], {10., 9.0548}, {0, 1}], 
         {PointSize[0.04], PointBox[{6., 10.}], PointBox[{14., 10.}]}, InsetBox[
          TagBox[
           StyleBox[
            TagBox["1",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->23.458909090909092`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            23.458909090909092`]& ], {10., -0.5}, {0, -1}]},
        "\"aebe/cfdf/ef.m\"",
        TooltipStyle->"TextStyling"],
       Annotation[#, "aebe/cfdf/ef.m", "Tooltip"]& ],
      AspectRatio->1,
      PlotRange->{{-1, 21}, {-1, 21}}], {0, 0}, {0, 0}, {22, 22}], InsetBox[
     GraphicsBox[
      TagBox[
       TooltipBox[
        {Thickness[0.005], 
         LineBox[{{1.8189894035458565`*^-12, 15.000000000003638`}, {9.999999999997726, 
          14.000000000003638`}}], 
         PolygonBox[{{5.597022314125994, 14.440297768587401`}, {4.363176198265607, 
          14.161687355328603`}, {4.442779173482406, 14.957717107496595`}}], InsetBox[
          TagBox[
           StyleBox[
            TagBox["e",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->29.323636363636364`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            29.323636363636364`]& ], {4.8457692355174515, 13.562492355174516}, {0, 1}], 
         LineBox[{{-7.503331289626658*^-12, 5.000000000003638}, {9.999999999988404, 6.}}], 
         PolygonBox[{{4.402977685874006, 5.440297768587401}, {5.636823801734393, 
          5.161687355328604}, {5.557220826517594, 5.9577171074965944`}}], InsetBox[
          TagBox[
           StyleBox[
            TagBox["e",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->29.323636363636364`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            29.323636363636364`]& ], {5.1542307644825485, 4.562492355174517}, {0, 1}], 
         LineBox[{{20.000000000002956`, 14.999999999996362`}, {10.000000000002956`, 
          13.999999999996362`}}], 
         PolygonBox[{{15.597022314125994`, 14.559702231412599`}, {14.363176198265608`, 
          14.838312644671397`}, {14.442779173482405`, 14.042282892503405`}}], InsetBox[
          TagBox[
           StyleBox[
            TagBox["e",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->29.323636363636364`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            29.323636363636364`]& ], {14.845769235517452, 15.437507644825484}, {0, -1}], 
         LineBox[{{19.999999999997726`, 4.999999999996362}, {9.999999999997726, 
          5.999999999996362}}], 
         PolygonBox[{{14.402977685874006`, 5.559702231412599}, {15.636823801734392`, 
          5.838312644671396}, {15.557220826517595`, 5.0422828925034056`}}], InsetBox[
          TagBox[
           StyleBox[
            TagBox["e",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->29.323636363636364`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            29.323636363636364`]& ], {15.154230764482548, 6.437507644825483}, {0, -1}], 
         LineBox[CompressedData["
1:eJxFlAlMnEUYhmcLWa2k9egBFLoszOzJ4sIOVmuVftWEltqGpU1kA5VjlaHQ
KL1MgbbQhEpoIr1CkR8xpKVaeiQ9FqtETDaUyzLgumCFlmIl7YrSg6Cpgu2u
g5rxT/5Mnsx/zPd97/tGO4s25M1BCKWJe3b99yLw1D9rGKAnD02vtRCod5/y
FjLBOdkociMBS+HI2CAX7AjN/ayIQJYVdb9KwwWHNDjLCJxJDYJPFcGQt6hs
LwEasWJlCFoCaPP7Vxa+SwANeu4UMcHF/a1xqQRGQ6PLBrjgNYf8pQYCK7Bt
6zIaAehwad3tGQw/uH6zKYpg++dr7/Vj6O7MfOVRQPDk19bg0xgOj+6aymaR
gLQV7UPVGC5qMxs7uOB9dR917cNgS04rMNOlgG75lmypwNARYrAfUQQbP9i5
/RiGxY2KdTog+M8nfMdbMGStc3TlMo2oJ8WhuYmhdzlzX+WC7eM5vrkETiSm
XqE0CtC46szWFwg8M/NeaYMiGCUZMjMItOsG7XOQFlDP0aJFOwlcXFCrXkYF
u72WbeUEHk61vlnABDfTLvVuAptOfbi6QZnd1wzm5hOYmNgy0c8F26tHHyQT
OBe88i0Vihb9mVvlWkpg9xpVG6WCHe6TnZMY7M/P0zMmGN245+rEYL55vaVO
Edxcs+q74xjWHewq6eWC40dM1QcweKpS9vgDgqvUe38ux+BCntYEGiOe79v+
bCWGu2kRhjwm2O78ZfXHGJS+W5fqFMEv1eyfaMMQdCAuhXPBky1nB3wYYv6a
vhYICC4ext4FBBqzMtdTisX8ulXpSQSGxj1NjAmedJzX5hJo+ip9WFEExz9c
NbaLgPl77e+cC9a+fLRX9Cfpj4C4/t+/bvkxhFIi3x+2NYt6ify+Jdy6SVGI
/H9e08lLnBN5vjG12oSQTp5fVeK9TKlO1leYGLU+n+lk/WEXbg/VKzrZH7sq
Prmf62T/aMnlChXSy/5+sWN5ZSLVy/4PE90b+Uwv5+MamBL16uX8qlr9r3Ou
l/N1PHaf8Af0cv7hi2sWJlCD1Edzxo4v32YGqZ/5TyefrlUMUl8b7xdMf8MN
Un+vjcSefxwwSH0+2t/TnkCNUr+ufIeGMaPUt+YOb6xXjFL/gzcGIr/lRumP
YhvdHIRM0j8xe+6mv0hN0l+/ZqX3FjKT9N/ZbRsufKKYpD/bnutQe7hJ+lcb
5f1JhczS32HGSkapWfqfTfq632FmmQ/VzgdQq5hlfgTXhc7r4WaZL2M5zpyZ
gFnmjzXDnx1HY2U+9V0rj8xlsTK/7vMjB48psTLfrPPP1V7lgv/Lv4BqdrXA
3yJp8BI=
          "]], InsetBox[
          TagBox[
           StyleBox[
            TagBox["\[Gamma]",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->29.323636363636364`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            29.323636363636364`]& ], {9.0548, 10.}, {1, 0}], 
         {PointSize[0.04], PointBox[{10., 14.}], PointBox[{10., 6.}]}, InsetBox[
          TagBox[
           StyleBox[
            TagBox["2",
             DisplayForm],
            FontFamily->"Helvetica",
            FontSize->23.458909090909092`],
           StyleForm[#, FontFamily -> "Helvetica", FontSize -> 
            23.458909090909092`]& ], {10., -0.5}, {0, -1}]},
        "\"aebf/cedf/ef.m\"",
        TooltipStyle->"TextStyling"],
       Annotation[#, "aebf/cedf/ef.m", "Tooltip"]& ],
      AspectRatio->1,
      PlotRange->{{-1, 21}, {-1, 21}}], {22, 0}, {0, 0}, {22, 22}]},
   AspectRatio->NCache[
     Rational[1, 2], 0.5],
   ImageSize->{512, 256},
   PlotRange->{{0, 44}, {0, 22}}], TraditionalForm]], "Print",
 CellLabel->"During evaluation of In[35]:="]

Parsing "slots" in templates

It would be nice if M2MD knows how to export "slots" of template boxes and objects. (TemplateBox, TemplateObject.)

See the attached notebook. (Remove the 2nd extension ".txt".)


To be more specific, I would like the prompt cell in notebook's section "Prompt Text" :

Cell[TextData[{
 "Rewrite the following text and convert some of it into emojis.\nThe emojis are all related to \
whatever is in the text.\n\n",
 Cell[BoxData[
  TemplateBox[{1, "\"\"", "Positional", TextData},
   "NotebookTemplateSlot"]]]
}], "Text",
 TaggingRules->{},
 CellChangeTimes->{},
 Background->GrayLevel[0.97],
 CellTags->"DefaultContent",
 CellID->439264869]

to be translated to Markdown as:

## Prompt Text

Rewrite the following text and convert some of it into emojis.
The emojis are all related to whatever is in the text.

`1`

instead of:

## Prompt Text

Rewrite the following text and convert some of it into emojis.
The emojis are all related to whatever is in the text.

![1qcf1uz1cr9wn](img/1qcf1uz1cr9wn.png)

M2MD-export-of-template-objects.nb.txt

MDExport cannot overwrite default ImagesFetchURL

I have used MDExport to export a notebook file like:

MDExport["test.md", NotebookOpen["test.nb"], "ImagesFetchURL" -> URL["img"]]

but I still got a wrong image url:

![0j6mbj99c3g8m](img\0j6mbj99c3g8m.png)

My environment:

  • Windows 10
  • Mathematica 12.1

Command Line Interface script

Please modify the package M2MD, so Command Line Interface (CLI) scripts can be made.

For example the following script does not work because M2MD requires front-end operations:

#!/usr/bin/env wolframscript -function

Block[{},
  Needs["M2MD`"];

  If[FileExistsQ[#1],
   fileName = StringReplace[FileNameSplit[#1][[-1]], {".nb" ~~ EndOfString -> ".md"}];

   SeedRandom[2323];

   M2MD`MDExport[fileName, NotebookRead[#1]];
   SystemOpen[fileName],

   (*ELSE*)
   Print["File does not exist."]]
 ] &

Support for lower-level headings

Please support Subsubsubsection and Subsubsubsubsection.

Create any heading, position the cursor at the start of it, and keep hitting tab to make it lower-level.

Add an option to render LaTeX as images

Since GitHub doesn't support LaTeX equations in its markdown, it might
be useful to have all equations rendered as images. This way the resulting
files can be easily added to a GitHub project wiki or a github.io site.

At the moment I can achieve the desired effect by simply commenting out

M2MD[style_, cell:_[BoxData @ FormBox[_, TraditionalForm], ___], OptionsPattern[]
] := MDElement["LaTeXBlock", BoxesToTeXString @ cell ];

Of course, this can be done in a more elegant way via a separate option of MDExport.

More careful treatment of TraditionalForm needed

In general, I would treat TraditionalForm output cells with more
care. Some users (like myself), might have it enabled as a standard
output format, so that every output cell is TraditionalForm by default.
Here is another problematic cell (containing LinkObject) that is not
treated properly in this setup

Cell[BoxData[
 FormBox[
  TemplateBox[{FrontEndObject[
     LinkObject["8ueui_shm", 3, 1]],16,"FrontEndObject[LinkObject[\"8ueui_shm\", 3, 1]]",
    "16",FormBox["\"ElAel-ElAel.nb\"", TraditionalForm],FormBox[
    "\"/home/vs/Downloads/ExportFC/ElAel-ElAel.nb\"", TraditionalForm]},
   "NotebookObject"], TraditionalForm]], "Output",
 CellLabel->"Out[66]="]

Bad conversion with mixed bold-italic

I have a cell which is all-italic, and starts with a bolded word. It is not converted correctly.

Cell[TextData[{
 StyleBox["Note:",
  FontWeight->"Bold",
  FontSlant->"Italic"],
 StyleBox[" foo bar baz.",
  FontSlant->"Italic"]
}], "Text"]

image

In[27]:= M2MD[
 Cell[TextData[{StyleBox["Note:", FontWeight -> "Bold", 
     FontSlant -> "Italic"], 
    StyleBox[" foo bar baz.", FontSlant -> "Italic"]}], "Text"]
 ]

Out[27]= "**Note:*** foo bar baz.*"

Expected output:

***Note:** foo bar baz.*

Part of this issue is illustrated by this smaller example:

In[28]:= M2MD[
 Cell[TextData[
   StyleBox["Test", FontWeight -> "Bold", FontSlant -> "Italic"]], 
  "Text"]]

Out[28]= "**Test**"

InputForm output

Try something //InputForm and convert that to Markdown. The output is not rendered as a code block.

Handle interpreted input, especially entities.

image

is interpreted as

focusAdmins2={Taiwan, Taiwan,Taichung, Taiwan};
focusAdmins1={Fujian, China};

It is because CopyAsPlainText does it. Otoh CopyAsInputText copies the string representation of boxes which are behind the 2D entities...

Will investigate,
WRI notified about a suboptimal behavior

String replacements of \[Rule] & co. do not work

I see that ProcessMDString is implemented and applied in M2MD[nb_NotebookObject,__] but when I export to Markdown I still see "[Rule]" and similar in the Markdown file.

(Also, maybe it is a good idea to have these string replacements specified with an option.)

Header style mappings

Currently sections are mapped header 4. I think this mapping is preferable:

StyleToElement[style_]:= Switch[style
, "Title",         "h1"
, "Subtitle",      "**h2**" (* Bold h2 *)
, "Subsubtitle",   "**h3**" (* Bold h3 *)
, "Section",       "h2"
, "Subsection",    "h3"
, "Subsubsection", "h4"
, _ , "Text"
]

TeXForm of 2 is not supported.

I started to transition the full FeynCalc documentation to Markdown using M2MD not so long ago,
but there are still some edge cases where I cannot obtain a proper LaTeX output and get only an image instead.
For example

M2MD[Cell[BoxData[
    FormBox[
      FractionBox["1", 
        TemplateBox[{"\"(\"", 
            SuperscriptBox[
              FormBox[
                FormBox["p", TraditionalForm], TraditionalForm], 2], 
       "\"+\"", 
            RowBox[{"2", " ", 
                RowBox[{"(", 
                    RowBox[{
                        FormBox[
                          FormBox["p", TraditionalForm], 
              TraditionalForm], 
                        
             FormBox["\"\[CenterDot]\"", TraditionalForm], 
                        FormBox[
                          FormBox["q", TraditionalForm], 
              TraditionalForm]}], ")"}]}], 
            RowBox[{"-", 
                SuperscriptBox["m", "2"]}], "\"+\"", 
            RowBox[{"\[ImaginaryI]", " ", "\"\[Eta]\""}], "\")\""},
          "RowDefault"]], TraditionalForm]], "Output",
   CellLabel -> "Out[13]="]]
During evaluation of In[15]:= TeXForm::unspt: TeXForm of 2 is not supported.

Out[15]= $$![1n6s7udnvjhyu](img/1n6s7udnvjhyu.png)$$

This happens for SFAD[{{p, 2 p . q}, m^2}] in FeynCalc. Is there perhaps a simple workaround for this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.