diff --git a/Cargo.lock b/Cargo.lock index bb2da1a..9f42256 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -435,6 +435,24 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cheezenotes" +version = "0.1.0" +dependencies = [ + "actix-files", + "actix-web", + "askama", + "askama_actix", + "clap", + "git2", + "lazy_static", + "mongodb", + "regex", + "rusqlite", + "serde", + "serde_json", +] + [[package]] name = "chrono" version = "0.4.23" @@ -1249,24 +1267,6 @@ dependencies = [ "digest", ] -[[package]] -name = "mdnotes" -version = "0.1.0" -dependencies = [ - "actix-files", - "actix-web", - "askama", - "askama_actix", - "clap", - "git2", - "lazy_static", - "mongodb", - "regex", - "rusqlite", - "serde", - "serde_json", -] - [[package]] name = "memchr" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index 2c8c149..4ac4247 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "mdnotes" +name = "cheezenotes" version = "0.1.0" edition = "2021" diff --git a/README.md b/README.md index f22bbcd..d03f685 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -mdnotes +cheezenotes ====== Notes utilisant la syntaxe MarkDown pour être rapide et facile à modifier. diff --git a/pages/index.md b/pages/index.md index f534687..0ed2a37 100644 --- a/pages/index.md +++ b/pages/index.md @@ -1,5 +1,5 @@ -# RustyNotes -L'objectif de RustyNotes est de pouvoir saisir des notes avec un minimum de formatage le plus rapidement possible. +# CheezeNotes +L'objectif de CheezeNotes est de pouvoir saisir des notes avec un minimum de formatage le plus rapidement possible. > Cette page est un bac à sable. Les modifications ne seront jamais enregistrées. > Pour réinitialiser la page, il suffit de la recharger. ## Utilisation @@ -13,6 +13,8 @@ Il y a 4 niveaux de titres : - `## titre 2` - `### titre 3` - `#### titre 4` +- `##### titre 5` +- `###### titre 6` ### **Gras**, *italic* etc. |:Syntaxe:|:Résultat:|:Ok ?:| |:`**gras**`|:**gras**|:| @@ -23,6 +25,7 @@ Il y a 4 niveaux de titres : |`___gras_italic___`|___gras_italic___|Non| |`__*gras_italic*__`|__*gras_italic*__|| |````texte formaté````|`texte formaté`|| +| `````````|```|| ### Liens Pour une url longue à laquelle on veut associer un libellé plus parlant, on choisira la syntaxe complète : - [Wikipedia Markdown](https://fr.wikipedia.org/wiki/Markdown) diff --git a/src/commons.rs b/src/commons.rs index aa5397a..08937c9 100644 --- a/src/commons.rs +++ b/src/commons.rs @@ -6,7 +6,7 @@ pub struct Arguments { #[arg(short, long, default_value_t = String::from("127.0.0.1"))] pub ip: String, /// Port to listen to - #[arg(short, long, default_value_t = 8081)] + #[arg(short, long, default_value_t = 8333)] pub port: u16, /// root of the url ending and starting with / #[arg(short, long, default_value_t = String::from("/"))] diff --git a/src/main.rs b/src/main.rs index 14c9a87..2cb7592 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ use actix_web::{web, App, HttpServer}; use actix_files; -use mdnotes::commons::{Arguments, AppData}; -use mdnotes::{ page, index }; +use cheezenotes::commons::{Arguments, AppData}; +use cheezenotes::{ page, index }; #[actix_web::main] async fn main() -> std::io::Result<()> { diff --git a/src/page.rs b/src/page.rs index f1c4517..8f04485 100644 --- a/src/page.rs +++ b/src/page.rs @@ -37,9 +37,9 @@ async fn page(path: web::Path<(String,)>, data: web::Data) -> impl Resp #[put("/page/{page}")] async fn save_page(body: String, path: web::Path<(String,)>) -> impl Responder { let pagename = &path.0; - if pagename == "index" { + /*if pagename == "index" { return HttpResponse::Ok(); - } + }*/ let filename = String::from("pages/") + pagename.as_str() + ".md"; let mut file = match fs::File::create(&filename) { Ok(f) => f, diff --git a/static/cheezenotes.css b/static/cheezenotes.css index 8fdf4b8..e5eb22a 100644 --- a/static/cheezenotes.css +++ b/static/cheezenotes.css @@ -55,7 +55,7 @@ textarea#ta { background-color: #cceeff; } -div#mdnotes { +div#cheezenotes { margin-top: 3rem; margin-left: auto; margin-right: auto; @@ -70,27 +70,27 @@ div#mdnotes { overflow-x: auto; } -div#mdnotes div.mdnotes_line { +div#cheezenotes div.cheezenotes_line { /* Pour firefox : white-space: pre; */ } -div#mdnotes span.tokenfictif { +div#cheezenotes span.tokenfictif { font-weight: 1; color: #1353b3; } -div#mdnotes:focus { +div#cheezenotes:focus { outline: none; } -div#mdnotes div.line { +div#cheezenotes div.line { border-bottom: 1px solid #dddddd; padding-top: 0rem; margin-top: 0rem; font-size: 8pt; } -div#mdnotes div.h1 { +div#cheezenotes div.h1 { font-size: 3rem; margin-top: 1.5rem; margin-bottom: 1.3rem; @@ -98,26 +98,37 @@ div#mdnotes div.h1 { border-bottom: 1px solid #dddddd; } -div#mdnotes div.h2 { +div#cheezenotes div.h2 { font-size: 2.3rem; margin-top: 1rem; margin-bottom: 1rem; } -div#mdnotes div.h3 { +div#cheezenotes div.h3 { font-size: 1.8rem; margin-top: 0.8rem; margin-bottom: 0.8rem; } -div#mdnotes div.h4 { - font-style: italic; - font-size: 1.4rem; +div#cheezenotes div.h4 { + font-size: 1.5rem; + margin-top: 0.5rem; + margin-bottom: 0.5rem; +} + +div#cheezenotes div.h5 { + font-size: 1.3rem; + margin-top: 0.5rem; + margin-bottom: 0.5rem; +} + +div#cheezenotes div.h6 { + font-size: 1.2rem; margin-top: 0.5rem; margin-bottom: 0.5rem; } -div#mdnotes div.bq1 { +div#cheezenotes div.bq1 { padding-top: 0.3rem; padding-bottom: 0.3rem; padding-left: .9rem; @@ -125,7 +136,7 @@ div#mdnotes div.bq1 { border-left: .3rem solid #446699; } -div#mdnotes div.bq2 { +div#cheezenotes div.bq2 { padding-top: 0.3rem; padding-bottom: 0.3rem; padding-left: .6rem; @@ -133,7 +144,7 @@ div#mdnotes div.bq2 { border-left: .6rem solid #5577aa; } -div#mdnotes div.bq3 { +div#cheezenotes div.bq3 { padding-top: 0.3rem; padding-bottom: 0.3rem; padding-left: .3rem; @@ -141,111 +152,111 @@ div#mdnotes div.bq3 { border-left: .9rem solid #6688bb; } -div#mdnotes div.ul1 { display:list-item; list-style-position: inside; padding-left: 2.2rem; padding-bottom: .2rem; padding-top: .2rem; } -div#mdnotes div.ul1.bq1 { padding-left: 1.9rem; } -div#mdnotes div.ul1.bq2 { padding-left: 1.6rem; } -div#mdnotes div.ul1.bq3 { padding-left: 1.3rem; } +div#cheezenotes div.ul1 { display:list-item; list-style-position: inside; padding-left: 2.2rem; padding-bottom: .2rem; padding-top: .2rem; } +div#cheezenotes div.ul1.bq1 { padding-left: 1.9rem; } +div#cheezenotes div.ul1.bq2 { padding-left: 1.6rem; } +div#cheezenotes div.ul1.bq3 { padding-left: 1.3rem; } -div#mdnotes div.ul2 { display:list-item; list-style-position: inside; list-style-type: circle; padding-left: 2.7rem; padding-bottom: .2rem; padding-top: .2rem; } -div#mdnotes div.ul2.bq1 { padding-left: 2.4rem; } -div#mdnotes div.ul2.bq2 { padding-left: 2.1rem; } -div#mdnotes div.ul2.bq3 { padding-left: 1.8rem; } +div#cheezenotes div.ul2 { display:list-item; list-style-position: inside; list-style-type: circle; padding-left: 2.7rem; padding-bottom: .2rem; padding-top: .2rem; } +div#cheezenotes div.ul2.bq1 { padding-left: 2.4rem; } +div#cheezenotes div.ul2.bq2 { padding-left: 2.1rem; } +div#cheezenotes div.ul2.bq3 { padding-left: 1.8rem; } -div#mdnotes div.ul3 { display:list-item; list-style-position: inside; list-style-type: square; padding-left: 3.2rem; padding-bottom: .2rem; padding-top: .2rem; } -div#mdnotes div.ul3.bq1 { padding-left: 2.9rem; } -div#mdnotes div.ul3.bq2 { padding-left: 2.6rem; } -div#mdnotes div.ul3.bq3 { padding-left: 2.3rem; } +div#cheezenotes div.ul3 { display:list-item; list-style-position: inside; list-style-type: square; padding-left: 3.2rem; padding-bottom: .2rem; padding-top: .2rem; } +div#cheezenotes div.ul3.bq1 { padding-left: 2.9rem; } +div#cheezenotes div.ul3.bq2 { padding-left: 2.6rem; } +div#cheezenotes div.ul3.bq3 { padding-left: 2.3rem; } -div#mdnotes div.ol1 { padding-left: 2.2rem; padding-bottom: .2rem; padding-top: .2rem; } -div#mdnotes div.ol1.bq1 { padding-left: 1.9rem; } -div#mdnotes div.ol1.bq2 { padding-left: 1.6rem; } -div#mdnotes div.ol1.bq3 { padding-left: 1.3rem; } +div#cheezenotes div.ol1 { padding-left: 2.2rem; padding-bottom: .2rem; padding-top: .2rem; } +div#cheezenotes div.ol1.bq1 { padding-left: 1.9rem; } +div#cheezenotes div.ol1.bq2 { padding-left: 1.6rem; } +div#cheezenotes div.ol1.bq3 { padding-left: 1.3rem; } -div#mdnotes div.ol2 { padding-left: 2.7rem; padding-bottom: .2rem; padding-top: .2rem; } -div#mdnotes div.ol2.bq1 { padding-left: 2.4rem; } -div#mdnotes div.ol2.bq2 { padding-left: 2.1rem; } -div#mdnotes div.ol2.bq3 { padding-left: 1.8rem; } +div#cheezenotes div.ol2 { padding-left: 2.7rem; padding-bottom: .2rem; padding-top: .2rem; } +div#cheezenotes div.ol2.bq1 { padding-left: 2.4rem; } +div#cheezenotes div.ol2.bq2 { padding-left: 2.1rem; } +div#cheezenotes div.ol2.bq3 { padding-left: 1.8rem; } -div#mdnotes div.ol3 { padding-left: 3.2rem; padding-bottom: .2rem; padding-top: .2rem; } -div#mdnotes div.ol3.bq1 { padding-left: 2.9rem; } -div#mdnotes div.ol3.bq2 { padding-left: 2.6rem; } -div#mdnotes div.ol3.bq3 { padding-left: 2.3rem; } +div#cheezenotes div.ol3 { padding-left: 3.2rem; padding-bottom: .2rem; padding-top: .2rem; } +div#cheezenotes div.ol3.bq1 { padding-left: 2.9rem; } +div#cheezenotes div.ol3.bq2 { padding-left: 2.6rem; } +div#cheezenotes div.ol3.bq3 { padding-left: 2.3rem; } -div#mdnotes span.oltoken { +div#cheezenotes span.oltoken { display: inline-block; width: 2rem; } -div#mdnotes span.lefttablespacer { +div#cheezenotes span.lefttablespacer { display: inline-block; } -div#mdnotes span.righttablespacer { +div#cheezenotes span.righttablespacer { display: inline-block; } -div#mdnotes div.tablerow { +div#cheezenotes div.tablerow { margin-top: .5rem; margin-bottom: .9rem; overflow-x: visible; } -div#mdnotes span.tablerow { +div#cheezenotes span.tablerow { white-space: nowrap; overflow-x: visible; border-bottom: 1px solid #dddddd; padding-bottom: 0.4rem; } -div#mdnotes div.firsttablerow { +div#cheezenotes div.firsttablerow { margin-top: 1.5rem; } -div#mdnotes div.firsttablerow span.tablerow { +div#cheezenotes div.firsttablerow span.tablerow { margin-bottom: 1.5rem; border-bottom: 1px solid #666666; font-weight: bold; } -div#mdnotes div.lasttablerow { +div#cheezenotes div.lasttablerow { margin-bottom: 1.5rem; } -div#mdnotes div.lasttablerow span.tablerow { +div#cheezenotes div.lasttablerow span.tablerow { margin-bottom: 1.5rem; border-bottom: none; } -div#mdnotes div.mdnotes_line span.token { +div#cheezenotes div.cheezenotes_line span.token { font-weight: 1; color: #1353b3; overflow: hidden; } -div#mdnotes div.mdnotes_line span.token { +div#cheezenotes div.cheezenotes_line span.token { font-size: 0; } -div#mdnotes:focus div.mdnotes_line span.token { +div#cheezenotes:focus div.cheezenotes_line span.token { font-size: inherit; } -div#mdnotes div.body { +div#cheezenotes div.body { margin-top: 0.5rem; margin-bottom: 0.5rem; } -div#mdnotes span.bold { +div#cheezenotes span.bold { font-weight: bold; } -div#mdnotes span.italic { +div#cheezenotes span.italic { font-style: italic; } -div#mdnotes span.mono { +div#cheezenotes span.mono { font-family: monospace; - color: #885511; + color: #555555; } \ No newline at end of file diff --git a/static/modules/caret.js b/static/modules/caret.js index 6208190..686d1f0 100644 --- a/static/modules/caret.js +++ b/static/modules/caret.js @@ -8,7 +8,7 @@ function getStartPositionInLine() { let position = range.startOffset; - if (obj.nodeName == 'DIV' && obj.classList.contains('mdnotes_line')) { + if (obj.nodeName == 'DIV' && obj.classList.contains('cheezenotes_line')) { return [obj, position]; } @@ -22,9 +22,9 @@ function getStartPositionInLine() { } else if (obj.length != null) { position += obj.length; } - } else if (obj.parentNode != null && obj.parentNode.classList != null && !obj.parentNode.classList.contains('mdnotes_line')) { + } else if (obj.parentNode != null && obj.parentNode.classList != null && !obj.parentNode.classList.contains('cheezenotes_line')) { obj = obj.parentNode; - } else if (obj.parentNode != null && obj.parentNode.classList != null && obj.parentNode.classList.contains('mdnotes_line')) { + } else if (obj.parentNode != null && obj.parentNode.classList != null && obj.parentNode.classList.contains('cheezenotes_line')) { line = obj.parentNode; obj = null; } else { diff --git a/static/modules/cheezenotes.js b/static/modules/cheezenotes.js index a7ee9e4..4259280 100644 --- a/static/modules/cheezenotes.js +++ b/static/modules/cheezenotes.js @@ -4,7 +4,7 @@ import { formatLine, load, save, formatTable, redrawTables, appendData, dpwidth function timeoutSave() { if (window.tos !== null) { window.clearTimeout(window.tos); - } + } window.tos = window.setTimeout(onsave, 5000); } @@ -20,9 +20,9 @@ function ontextarea(e) { function onsave(e) { let saveButton = document.getElementById('saveButton'); saveButton.disabled = true; - let text = save(document.getElementById('ta'), document.getElementById('mdnotes')); + let text = save(document.getElementById('ta'), document.getElementById('cheezenotes')); var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function() { + xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status != 200) { saveButton.disabled = false; alert(xhttp.responseText); @@ -33,11 +33,16 @@ function onsave(e) { } function onload(e) { - load(document.getElementById('ta'), document.getElementById('mdnotes')); + load(document.getElementById('ta'), document.getElementById('cheezenotes')); } function onedit(e) { - console.log('onedit'); + + if (e.inputType == 'insertCompositionText') { + e.preventDefault(); + return false; + } + timeoutSave(); saveButton.disabled = false; let ret = getStartPositionInLine(); @@ -45,14 +50,14 @@ function onedit(e) { let position = ret[1]; if (line.innerText == '\n') { - line.className = 'mdnotes_line'; + line.className = 'cheezenotes_line'; line.classList.add('body'); return; } let prevline = line.previousSibling; if (prevline != null && prevline.innerText == '\n') { - prevline.className = 'mdnotes_line'; + prevline.className = 'cheezenotes_line'; prevline.classList.add('body'); } @@ -84,35 +89,35 @@ function onkeydown(e) { return false; } -function onkeypress(e) { +function onkeyup(e) { if (e.key !== 'Escape') { -return true; + return true; } - e.preventDefault(); - document.getElementById('mdnotes').blur(); - if (saveButton.disabled == false) { - onsave(); - } - return false; + e.preventDefault(); + document.getElementById('cheezenotes').blur(); + if (saveButton.disabled == false) { + onsave(); + } + return false; } -function onkeyup(e) { +function onkeypress(e) { if (e.key !== 'Escape') { return true; } - e.preventDefault(); - document.getElementById('mdnotes').blur(); - if (saveButton.disabled == false) { - onsave(); - } - return false; + e.preventDefault(); + document.getElementById('cheezenotes').blur(); + if (saveButton.disabled == false) { + onsave(); + } + return false; } function onpaste(e) { e.preventDefault(); timeoutSave(); let data = e.clipboardData.getData('text/plain'); - appendData(document.getElementById('mdnotes'), data); + appendData(document.getElementById('cheezenotes'), data); saveButton.disabled = false; return false; } @@ -123,11 +128,11 @@ function oncopy(e) { function onlockbutton(e) { let lockButton = document.getElementById('lockButton'); - let mdnotes = document.getElementById('mdnotes'); + let cheezenotes = document.getElementById('cheezenotes'); if (lockButton.checked) { - mdnotes.contentEditable = false; + cheezenotes.contentEditable = false; } else { - mdnotes.contentEditable = true; + cheezenotes.contentEditable = true; } } @@ -147,21 +152,21 @@ function init(pagename = null) { /*if (pagename != null) { window.history.replaceState(null, '', '/page/' + pagename); }*/ - let mdnotesdiv = document.getElementById('mdnotes'); - - dpwidth(mdnotesdiv); - - mdnotesdiv.addEventListener('input', onedit); - mdnotesdiv.addEventListener('keyup', onkeyup); - mdnotesdiv.addEventListener('keypress', onkeypress); - mdnotesdiv.addEventListener('keydown', onkeydown); - mdnotesdiv.addEventListener('paste', onpaste); - mdnotesdiv.addEventListener('copy', oncopy); - mdnotesdiv.addEventListener('blur', () => {redrawTables(mdnotesdiv); onsave()}); - mdnotesdiv.addEventListener('focus', () => {redrawTables(mdnotesdiv, dpwidth());}); - mdnotesdiv.addEventListener('drag', ondrag); - mdnotesdiv.addEventListener('dragenter', ondragenter); - mdnotesdiv.addEventListener('dragleave', ondragleave); + let cheezenotesdiv = document.getElementById('cheezenotes'); + + dpwidth(cheezenotesdiv); + + cheezenotesdiv.addEventListener('input', onedit); + cheezenotesdiv.addEventListener('keyup', onkeyup); + cheezenotesdiv.addEventListener('keypress', onkeypress); + cheezenotesdiv.addEventListener('keydown', onkeydown); + cheezenotesdiv.addEventListener('paste', onpaste); + cheezenotesdiv.addEventListener('copy', oncopy); + cheezenotesdiv.addEventListener('blur', () => { redrawTables(cheezenotesdiv); onsave() }); + cheezenotesdiv.addEventListener('focus', () => { redrawTables(cheezenotesdiv, dpwidth()); }); + cheezenotesdiv.addEventListener('drag', ondrag); + cheezenotesdiv.addEventListener('dragenter', ondragenter); + cheezenotesdiv.addEventListener('dragleave', ondragleave); let saveButton = document.getElementById('saveButton'); saveButton.disabled = true; diff --git a/static/modules/md.js b/static/modules/md.js index 8a1c986..186633e 100644 --- a/static/modules/md.js +++ b/static/modules/md.js @@ -80,16 +80,16 @@ function emsp() { function onlinkin(e) { let link = e.currentTarget; - if (document.getElementById('mdnotes') !== document.activeElement) { - document.getElementById('mdnotes').contentEditable = false; + if (document.getElementById('cheezenotes') !== document.activeElement) { + document.getElementById('cheezenotes').contentEditable = false; } } function onlink(e) { - let mdnotes = document.getElementById('mdnotes'); - if (mdnotes.contentEditable == 'false') { + let cheezenotes = document.getElementById('cheezenotes'); + if (cheezenotes.contentEditable == 'false') { e.preventDefault(); - mdnotes.contentEditable = true; + cheezenotes.contentEditable = true; let link = e.currentTarget; if (link.host !== document.location.host) { open(link.href); @@ -103,16 +103,16 @@ function onlink(e) { } function onlinkout(e) { - let mdnotes = document.getElementById('mdnotes'); - if (mdnotes.contentEditable == 'false') { - mdnotes.contentEditable = true; + let cheezenotes = document.getElementById('cheezenotes'); + if (cheezenotes.contentEditable == 'false') { + cheezenotes.contentEditable = true; } } function formatLine(line) { let token = null; let elem = document.createElement('div'); - elem.classList.add('mdnotes_line'); + elem.classList.add('cheezenotes_line'); if (line == '' || line == '\n') { elem.classList.add('body'); elem.innerHTML = '
'; @@ -129,9 +129,15 @@ function formatLine(line) { ret = removeLink(line); console.log('removeLink ' + ret[0]); - if (line.match(/^\s*-{3,}\s*$/)) { - token = /^(\s*-{3,}\s*)$/ + if (line.match(/^\s*_{3,}\s*$/)) { + token = /^(\s*_{3,}\s*)$/ elem.classList.add('line'); + } else if (line.match(/^\s*######(\s|$)/i)) { + token = /^(\s*######(\s|$))/i; + elem.classList.add('h6'); + } else if (line.match(/^\s*#####(\s|$)/i)) { + token = /^(\s*#####(\s|$))/i; + elem.classList.add('h5'); } else if (line.match(/^\s*####(\s|$)/i)) { token = /^(\s*####(\s|$))/i; elem.classList.add('h4'); @@ -282,11 +288,11 @@ function addTableLine(line) { return line; } -function redrawTables(mdnotes, dpwidth = 0) { - if (mdnotes.childNodes.length == 0) { +function redrawTables(cheezenotes, dpwidth = 0) { + if (cheezenotes.childNodes.length == 0) { return; } - let child = mdnotes.childNodes[0]; + let child = cheezenotes.childNodes[0]; let firsttableline = null; while(child != null) { if (firsttableline == null) { diff --git a/templates/page.html b/templates/page.html index 85e47a2..ed782f0 100644 --- a/templates/page.html +++ b/templates/page.html @@ -13,8 +13,8 @@
-
-
+
+