Skip to content

Commit

Permalink
Small tweaks (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoskim authored Oct 10, 2024
1 parent fdaa041 commit a133a8b
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 74 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Check out discussions page for status:

https://github.com/mkoskim/mawejs/discussions/88

**Oct 10, 2024:** I added mechanism to create **unnumbered chapters**: creating, loading, saving and exporting those. You can use these for various purposes, when you want a chapter element, but don't want it to mess with chapter numbering.

**Oct 9, 2024:** I worked a bit with file imports. When importing, MaweJS now has dialog to **import preview**, where you can see what's going to be imported. You can set some options, like newlines (single or double), and patterns to separate parts and scenes. I added "mammoth" library to read **.docx** files and convert them to text for importing. Furthermore, there is now new **Import From Clipboard**. You can copy text from various sources, and choosing this option opens the clipboard content in import preview.

**Oct 7, 2024:** MaweJS now stores **daily word counts** when saving the document. It can now show you how many words (actual words) you have written today, and later you can see the progression from "Statistics" view.
Expand Down
3 changes: 2 additions & 1 deletion src/gui/common/styles/sheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@
/* Chapter */ .Sheet h5 {
font-family: Arial, Helvetica, sans-serif;
font-size: inherit;
font-weight: bold;
color: #888;
/*
font-weight: normal;
font-weight: bold;
padding-top: 4pt;
padding-bottom: 4pt;
text-align: center;
Expand Down
20 changes: 10 additions & 10 deletions src/gui/export/formatDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function FormatBody(format, story) {
const pgbreak = exports.type === "long"
*/

return format["file"](
return format.file(
mawe.info(head),
FormatBody(body.chapters),
options
Expand All @@ -81,11 +81,11 @@ export function FormatBody(format, story) {
function FormatBody(chapters) {
const content = chapters.map(FormatChapter).filter(p => p)

return format["body"](content, options.chapter)
return format.body(content, options.chapter)
}

function FormatChapter(chapter) {
return format["chapter"](
return format.chapter(
FormatChapterHead(chapter),
chapter.children.filter(e => e.type === "scene").map(FormatScene).filter(s => s),
options.scene
Expand All @@ -99,10 +99,10 @@ export function FormatBody(format, story) {
const {unnumbered} = head

if(unnumbered) {
return format["hchapter"](id, undefined, elemAsText(head), options.chapter.unnumbered)
return format.hchapter(id, undefined, elemAsText(head), options.chapter.unnumbered)
} else {
chapternum = chapternum + 1
return format["hchapter"](id, chapternum, elemAsText(head), options.chapter.numbered)
return format.hchapter(id, chapternum, elemAsText(head), options.chapter.numbered)
}
}

Expand All @@ -118,14 +118,14 @@ export function FormatBody(format, story) {

//if(chapters.element === "scene") scenenum = scenenum + 1

return format["scene"]("", splits)
return format.scene("", splits)
}

function FormatSplit(split) {
const paragraphs = split.map(FormatParagraph).filter(p => p?.length)
//console.log(split, "->", content)
if (!paragraphs.length) return null
return format["split"](paragraphs)
return format.split(paragraphs)
}

function FormatParagraph(p) {
Expand All @@ -136,9 +136,9 @@ export function FormatBody(format, story) {
}

function FormatMarks(split) {
var text = format["text"](split.text)
if(split.bold) text = format["b"](text)
if(split.italic) text = format["i"](text)
var text = format.text(split.text)
if(split.bold) text = format.b(text)
if(split.italic) text = format.i(text)
return text
}
}
23 changes: 12 additions & 11 deletions src/gui/export/formatHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
//
// ****************************************************************************

import {elemAsText, elemName} from "../../document"
import {getHeader} from "../../document/head"

// ****************************************************************************

export const formatHTML = {
// Info
"suffix": ".html",
suffix: ".html",

// File
"file": (head, content, options) => {
file: (head, content, options) => {
const {author, title, subtitle} = head
const headinfo = getHeader(head)
return `\
Expand All @@ -32,25 +31,25 @@ ${content}
// Blocks
//---------------------------------------------------------------------------

"body": (chapters, options) => {
body: (chapters, options) => {
return chapters.join(getSeparator(options.separator))
},

"chapter": (head, scenes, options) => {
chapter: (head, scenes, options) => {
return head + scenes.join(getSeparator(options.separator))
},

"scene": (head, splits) => {
scene: (head, splits) => {
return head + splits.join("<br/>\n")
},

"split": (paragraphs) => paragraphs.join("\n"),
split: (paragraphs) => paragraphs.join("\n"),

//---------------------------------------------------------------------------
// Headings
//---------------------------------------------------------------------------

"hchapter": (id, number, name, options) => {
hchapter: (id, number, name, options) => {
if(options.skip) return `<div id=${id}></div>`

const pgbreak = options.pgbreak ? "<hr/>\n" : ""
Expand All @@ -61,6 +60,8 @@ ${content}
return `${pgbreak}<h2 id="${id}">${head}</h2>`
},

hscene: undefined,

//---------------------------------------------------------------------------
// Paragraphs
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -91,11 +92,11 @@ function escape(text) {
.replaceAll('&', "&amp;")
.replaceAll('<', "&lt;")
.replaceAll('>', "&gt;")
.replaceAll('"', "&quot;")

// If you have copy-pasted text, you may have these
.replaceAll('“', "&quot;")
.replaceAll('”', "&quot;")
.replaceAll('“', '"')
.replaceAll('”', '"')
//.replaceAll('"', "&quot;")
.replaceAll('…', "...")
)
}
17 changes: 9 additions & 8 deletions src/gui/export/formatRTF.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ ${paperA4}

export const formatRTF = {
// Info
"suffix": ".rtf",
suffix: ".rtf",

// File
"file": (head, content, options) => {
file: (head, content, options) => {
const pgbreak = options.pgbreak ? "\\page" : ""

const {author, title, subtitle} = head
Expand Down Expand Up @@ -87,26 +87,26 @@ ${content}
//---------------------------------------------------------------------------
// Joining elements

"body": (chapters, options) => {
body: (chapters, options) => {
return chapters.join(getSeparator(options.separator))
},

"chapter": (head, scenes, options) => {
chapter: (head, scenes, options) => {
const {separator} = options
return head + scenes.join(getSeparator(separator))
},

"scene": (head, splits) => {
scene: (head, splits) => {
return head + splits.join("\n")
},

"split": (paragraphs) => "{\\sb480" + paragraphs.join("{\\fi567"),
split: (paragraphs) => "{\\sb480" + paragraphs.join("{\\fi567"),

//---------------------------------------------------------------------------
// Headings
//---------------------------------------------------------------------------

"hchapter": (id, number, name, options) => {
hchapter: (id, number, name, options) => {
if(options.skip) return ""

const pgbreak = options.pgbreak ? "\\pagebb" : "\\sb480"
Expand All @@ -117,6 +117,8 @@ ${content}
return `{${pgbreak}\\b\\fs28 ${head}\\par}\n`
},

hscene: undefined,

//---------------------------------------------------------------------------

// Paragraph styles
Expand All @@ -129,7 +131,6 @@ ${content}
"i": (text) => `{\\i ${text}}`,
"text": (text) => escape(text),


//---------------------------------------------------------------------------
}

Expand Down
42 changes: 14 additions & 28 deletions src/gui/export/formatTEX.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const commonHeading = `\
`

function renewCommands(options, sides) {
const pgbreak = options.long
const newpage = sides === "oneside" ? "\\newpage" : "\\cleartooddpage"

return `\
Expand All @@ -52,7 +53,7 @@ function renewCommands(options, sides) {
{\\large \\@subtitle \\par}
}
}
${options.pgbreak ? newpage : "\\vskip 48pt"}
${pgbreak ? newpage : "\\vskip 48pt"}
}
\\newcommand\\innertitle{{\\center{\\Large\\@title\\vskip 48pt}}}
Expand All @@ -63,7 +64,7 @@ function renewCommands(options, sides) {
}
\\renewcommand\\chapter[2]{
${options.pgbreak ? newpage : "\\vskip 36pt"}
${pgbreak ? newpage : "\\vskip 36pt"}
\\begin{center}
\\if@titlepage
\\ifthenelse{\\equal{#1}{}}{}{\\RNum{#1}\\vskip 12pt}
Expand All @@ -73,7 +74,7 @@ function renewCommands(options, sides) {
\\ifthenelse{\\equal{#2}{}}{}{\\textbf{#2}}
\\fi
\\end{center}
${options.pgbreak ? "\\vskip 48pt" : "\\vskip 18pt"}
${pgbreak ? "\\vskip 48pt" : "\\vskip 18pt"}
}
\\newcommand\\separator[1]{
Expand Down Expand Up @@ -129,10 +130,10 @@ ${renewCommands(options, sides)}

const formatTEX = {
// Info
"suffix": ".tex",
suffix: ".tex",

// File
"file": (head, content, options) => {
file: (head, content, options) => {
const sides = "oneside"
const titlepage = options.long ? "titlepage" : "notitlepage"
const frontmatter = options.long ? "\\frontmatter\\pagestyle{empty}" : "\\pagestyle{plain}"
Expand Down Expand Up @@ -164,49 +165,33 @@ ${backmatter}
//---------------------------------------------------------------------------
// Joining elements

"body": (chapters, options) => {
body: (chapters, options) => {
return chapters.join(getSeparator(options.separator))
},

"chapter": (head, scenes, options) => {
chapter: (head, scenes, options) => {
return head + scenes.join(getSeparator(options.separator))
},

"scene": (head, splits) => {
scene: (head, splits) => {
return head + splits.join("\n\n")
},

"split": (paragraphs) => "\\noindent " + paragraphs.join("\n\n"),
split: (paragraphs) => "\\noindent " + paragraphs.join("\n\n"),

//---------------------------------------------------------------------------
// Headings
//---------------------------------------------------------------------------

"hchapter": (id, number, name, options) => {
hchapter: (id, number, name, options) => {
if(options.skip) return ""

//const pgbreak = options.pgbreak ? "<hr/>\n" : ""
const chnum = options.number ? [escape(`${options.prefix ?? ""}${number}`)] : []
const title = options.name ? [escape(name)] : []
//const head = [ ...numbering, ...title].join(". ")

return `\n\n\\chapter{${chnum}}{${title}}\n\n`
//return `${pgbreak}<h2 id="${id}">${head}</h2>`
},

/*
const size = pgbreak ? "\\Large" : "\\large"
const sb = pgbreak ? "\\cleartooddpage" : "\n\n"
const sa = "\n\n\\par\\null\n\n"
switch (type) {
case "numbered": return `${sb}{\\noindent${size} ${chnum}.}${sa}`
case "named": return `${sb}{\\noindent${size} ${chnum}. ${escape(elem.name)}}${sa}`
default: break;
}
return ""
*/

//---------------------------------------------------------------------------

// Paragraph styles
Expand Down Expand Up @@ -236,13 +221,14 @@ export const formatTEX2 = {
...formatTEX,

// File
"file": (head, content, options) => {
file: (head, content, options) => {
const sides = "twoside"
//const titlepage = options.pgbreak ? "titlepage" : "notitlepage"
//const frontmatter = options.pgbreak ? "\\frontmatter\\pagestyle{empty}" : ""
//const mainmatter = options.pgbreak ? "\\mainmatter\\pagestyle{plain}" : ""
//const backmatter = options.pgbreak ? "\\backmatter\\pagestyle{empty}" : ""

const pgbreak = options.long
const titlepage = "titlepage"
const frontmatter = "\\frontmatter\\pagestyle{empty}"
const mainmatter = "\\mainmatter\\pagestyle{plain}"
Expand All @@ -261,7 +247,7 @@ ${frontmatter}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
${mainmatter}
${options.pgbreak ? "" : "\\innertitle"}
${pgbreak ? "" : "\\innertitle"}
${content}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
Loading

0 comments on commit a133a8b

Please sign in to comment.