Here is how you could auto-extract separately the images and the text from your "Package" file.
First we need to uncomment the commented lines in order to be able to extract the complete Mathematica expressions:
text = Import["OSF Lab Report 1.m", "Lines"];
text2 = StringJoin[StringTrim[#, "(*" | "*)"] <> "\n" & /@ text];
Now we match complete expressions with Head Image using the regexp developed by Xavier in this post (I've simplified it for matching only balanced square braces []):
images = StringCases[text2,
"Image" ~~ RegularExpression["(?P<a>\\[([^\\[\\]]|(?P>a))*\\])"]];
Now you can convert them directly into images:
ToExpression /@ images
All images except the last are converted successfully. The ColorProfileData of the last image contains damaged CompressedData, hence we have to remove the ColorSpace information completely in order to obtain a valid image:
code = ToHeldExpression[images[[-1]]];
Delete[code, {1, 3}] // ReleaseHold
The text without images can be obtained using the same regexp:
text3 = StringReplace[text2,
"Image" ~~ RegularExpression["(?P<a>\\[([^\\[\\]]|(?P>a))*\\])"] -> ""];
Now you can make an editable Cell containing all the text with things like \[CapitalDelta]d already properly formatted:
CellPrint[Cell[text3]]
(but things like Subscript[L, 1] you still have to format manually).
An alternative is to export it as a TXT file:
Export["OSF Lab Report 1 - Text Only.txt", text3]
The rest is up to you.
Notebook/.{".m"->".nb"}would work? – bill s Oct 01 '16 at 14:39Filein the top bar, thenSave As..., and select.nbas the file extension. If you open the.nbfile, everything will be in Text style. Select the cells you want to convert to code style, and press Alt+9. – JungHwan Min Oct 01 '16 at 14:49