mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
ide: Markdown export improvements
This commit is contained in:
parent
00684eeddb
commit
1d6d0b2bf7
5 changed files with 71 additions and 14 deletions
|
|
@ -259,8 +259,8 @@ void TopicEditor::FileBar(Bar& bar)
|
||||||
bar.Add("Export group to PDF..", THISBACK(ExportGroupPdf));
|
bar.Add("Export group to PDF..", THISBACK(ExportGroupPdf));
|
||||||
bar.Add("Export to HTML..", THISBACK(ExportHTML));
|
bar.Add("Export to HTML..", THISBACK(ExportHTML));
|
||||||
bar.Add("Export group to HTML..", THISBACK(ExportGroupHTML));
|
bar.Add("Export group to HTML..", THISBACK(ExportGroupHTML));
|
||||||
bar.Add("Export as GitHub Markdown", [=] {
|
bar.Add("Export as GitHub Markdown..", [=] {
|
||||||
ExportMarkdown(editor.GetQTF());
|
ExportMarkdown(editor.GetQTF(), GetFileTitle(topicpath));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,6 @@ void QTFEdit(String& text);
|
||||||
|
|
||||||
void IdeHelpButton(Button& help, const String& link);
|
void IdeHelpButton(Button& help, const String& link);
|
||||||
|
|
||||||
void ExportMarkdown(const char *qtf);
|
void ExportMarkdown(const char *qtf, const char *name);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
LAYOUT(ExportMDLayout, 400, 488)
|
LAYOUT(ExportMDLayout, 400, 488)
|
||||||
ITEM(Upp::Label, dv___0, SetLabel(t_("\001[g Markdown text copied! Since Markdown doesn't natively embed images, please use the table to manually copy images for their respective placeholders (IMAGE:N).")).SetVAlign(Upp::ALIGN_TOP).LeftPosZ(160, 236).TopPosZ(4, 88))
|
ITEM(Upp::Label, dv___0, SetLabel(t_("\001[g Markdown text copied! Since Markdown doesn't natively embed images, please use the table to manually copy images for their respective placeholders (IMAGE:N).")).SetVAlign(Upp::ALIGN_TOP).LeftPosZ(160, 236).TopPosZ(4, 80))
|
||||||
ITEM(Upp::ArrayCtrl, list, LeftPosZ(4, 150).TopPosZ(4, 480))
|
ITEM(Upp::ArrayCtrl, list, LeftPosZ(4, 150).TopPosZ(4, 480))
|
||||||
ITEM(Upp::Button, exit, SetLabel(t_("Close")).LeftPosZ(332, 64).TopPosZ(460, 24))
|
ITEM(Upp::Button, exit, SetLabel(t_("Close")).LeftPosZ(332, 64).TopPosZ(460, 24))
|
||||||
|
ITEM(Upp::Button, doexport, SetLabel(t_("Export")).LeftPosZ(332, 64).TopPosZ(148, 24))
|
||||||
|
ITEM(Upp::Label, dv___4, SetLabel(t_("\001[g Alternatively, you can export Markdown to a folder with image files:")).SetVAlign(Upp::ALIGN_TOP).LeftPosZ(160, 236).TopPosZ(88, 32))
|
||||||
|
ITEM(Upp::EditString, dir, LeftPosZ(160, 212).TopPosZ(124, 19))
|
||||||
|
ITEM(Upp::Button, sel, LeftPosZ(376, 20).TopPosZ(124, 20))
|
||||||
|
ITEM(Upp::ImageCtrl, preview, LeftPosZ(156, 240).TopPosZ(212, 244))
|
||||||
END_LAYOUT
|
END_LAYOUT
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ void IdeQtfDes::EditMenu(Bar& menu)
|
||||||
{
|
{
|
||||||
EditTools(menu);
|
EditTools(menu);
|
||||||
menu.Separator();
|
menu.Separator();
|
||||||
menu.Add("Export as GitHub Markdown", [=] {
|
menu.Add("Export as GitHub Markdown..", [=] {
|
||||||
ExportMarkdown(GetQTF());
|
ExportMarkdown(GetQTF(), GetFileTitle(filename));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@
|
||||||
#include <CtrlCore/lay.h>
|
#include <CtrlCore/lay.h>
|
||||||
|
|
||||||
struct ExportMD : WithExportMDLayout<TopWindow> {
|
struct ExportMD : WithExportMDLayout<TopWindow> {
|
||||||
|
bool exporting;
|
||||||
|
String qtf;
|
||||||
|
String name;
|
||||||
String md;
|
String md;
|
||||||
Vector<RichObject> img;
|
Vector<RichObject> img;
|
||||||
|
|
||||||
|
|
@ -13,7 +16,7 @@ struct ExportMD : WithExportMDLayout<TopWindow> {
|
||||||
|
|
||||||
static bool IsPreformatted(const RichPara& p);
|
static bool IsPreformatted(const RichPara& p);
|
||||||
|
|
||||||
void Do(const char *qtf);
|
void Do(const char *qtf, const char *name);
|
||||||
|
|
||||||
ExportMD();
|
ExportMD();
|
||||||
};
|
};
|
||||||
|
|
@ -21,6 +24,39 @@ struct ExportMD : WithExportMDLayout<TopWindow> {
|
||||||
ExportMD::ExportMD()
|
ExportMD::ExportMD()
|
||||||
{
|
{
|
||||||
CtrlLayoutExit(*this, "Export as GitHub Markdown");
|
CtrlLayoutExit(*this, "Export as GitHub Markdown");
|
||||||
|
sel.SetImage(Upp::CtrlImg::Dir());
|
||||||
|
sel << [=] {
|
||||||
|
dir <<= Nvl(SelectDirectory(), ~~dir);
|
||||||
|
};
|
||||||
|
|
||||||
|
list.NoWantFocus();
|
||||||
|
|
||||||
|
doexport << [=] {
|
||||||
|
exporting = true;
|
||||||
|
Export(ParseQTF(qtf));
|
||||||
|
String d = ~dir;
|
||||||
|
if(!DirectoryExists(d)) {
|
||||||
|
if(!PromptYesNo("Create directory [* \1 " + d))
|
||||||
|
return;
|
||||||
|
if(!RealizeDirectory(d))
|
||||||
|
Exclamation("Cannot create [* \1 " + d);
|
||||||
|
}
|
||||||
|
Progress pi("Exporting", 2 * img.GetCount());
|
||||||
|
SaveFile(d + "/" + name + ".md", md);
|
||||||
|
for(int i = 0; i < img.GetCount(); i++) {
|
||||||
|
for(int half = 0; half < 2; half++) {
|
||||||
|
if(pi.StepCanceled())
|
||||||
|
return;
|
||||||
|
RichObjectPaintInfo pi;
|
||||||
|
pi.ink = SBlack();
|
||||||
|
Image m = img[i].ToImage(img[i].GetPixelSize(), pi);
|
||||||
|
PNGEncoder().SaveFile(d + "/" + AsString(i) + (half ? "_half.png" : ".png"),
|
||||||
|
half ? Downscale2x(m) : m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exporting = false;
|
||||||
|
Export(ParseQTF(qtf));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportMD::Export(const RichPara& p)
|
void ExportMD::Export(const RichPara& p)
|
||||||
|
|
@ -33,7 +69,11 @@ void ExportMD::Export(const RichPara& p)
|
||||||
const RichPara::Part& part = p.part[i];
|
const RichPara::Part& part = p.part[i];
|
||||||
int q;
|
int q;
|
||||||
if(part.object) {
|
if(part.object) {
|
||||||
md << "IMAGE:" << img.GetCount();
|
int n = img.GetCount();
|
||||||
|
if(exporting)
|
||||||
|
md << "";
|
||||||
|
else
|
||||||
|
md << "IMAGE:" << n;
|
||||||
img << part.object;
|
img << part.object;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -127,6 +167,8 @@ bool ExportMD::IsPreformatted(const RichPara& p)
|
||||||
|
|
||||||
void ExportMD::Export(const RichText& txt)
|
void ExportMD::Export(const RichText& txt)
|
||||||
{
|
{
|
||||||
|
img.Clear();
|
||||||
|
md.Clear();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i < txt.GetPartCount())
|
while(i < txt.GetPartCount())
|
||||||
if(txt.IsPara(i)) {
|
if(txt.IsPara(i)) {
|
||||||
|
|
@ -155,34 +197,44 @@ void ExportMD::Export(const RichText& txt)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportMD::Do(const char *qtf)
|
void ExportMD::Do(const char *qtf_, const char *name_)
|
||||||
{
|
{
|
||||||
|
name = name_;
|
||||||
|
dir <<= GetHomeDirectory() + "/" + name;
|
||||||
|
qtf = qtf_;
|
||||||
Export(ParseQTF(qtf));
|
Export(ParseQTF(qtf));
|
||||||
WriteClipboardText(md);
|
WriteClipboardText(md);
|
||||||
if(img.GetCount()) {
|
if(img.GetCount()) {
|
||||||
list.SetLineCy(DPI(28));
|
list.SetLineCy(DPI(28));
|
||||||
list.AddColumn("Image").Ctrls([&](int ii, One<Ctrl>& ctrl) {
|
list.AddColumn("Image").Ctrls([&](int ii, One<Ctrl>& ctrl) {
|
||||||
|
int half = ii & 1;
|
||||||
|
ii /= 2;
|
||||||
Button& b = ctrl.Create<Button>();
|
Button& b = ctrl.Create<Button>();
|
||||||
|
b.NoWantFocus();
|
||||||
b.SetImage(CtrlImg::copy());
|
b.SetImage(CtrlImg::copy());
|
||||||
b.SetLabel("Copy IMAGE:" + AsString(ii));
|
b.SetLabel("Copy IMAGE:" + AsString(ii) + (half ? " 50%" : ""));
|
||||||
b << [=] {
|
b << [=] {
|
||||||
if(ii >= 0 && ii < img.GetCount()) {
|
if(ii >= 0 && ii < img.GetCount()) {
|
||||||
RichObjectPaintInfo pi;
|
RichObjectPaintInfo pi;
|
||||||
pi.ink = SBlack();
|
pi.ink = SBlack();
|
||||||
WriteClipboardImage(img[ii].ToImage(img[ii].GetPixelSize(), pi));
|
Image m = img[ii].ToImage(img[ii].GetPixelSize(), pi);
|
||||||
|
preview.SetImage(CoRescaleFilter(m, GetFitSize(m.GetSize(), preview.GetSize()), FILTER_BILINEAR));
|
||||||
|
WriteClipboardImage(half ? Downscale2x(m) : m);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
for(int i = 0; i < img.GetCount(); i++)
|
for(int i = 0; i < img.GetCount(); i++) {
|
||||||
list.Add();
|
list.Add();
|
||||||
|
list.Add();
|
||||||
|
}
|
||||||
Run();
|
Run();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PromptOK("Markdown copied to clipboard.");
|
PromptOK("Markdown copied to clipboard.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportMarkdown(const char *qtf)
|
void ExportMarkdown(const char *qtf, const char *name)
|
||||||
{
|
{
|
||||||
ExportMD md;
|
ExportMD md;
|
||||||
md.Do(qtf);
|
md.Do(qtf, name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue