mirror of
https://github.com/storytold/deckcraft.git
synced 2026-10-27 03:56:50 -06:00
# Conflicts: # crates/engine/src/tests.rs
This commit is contained in:
@@ -89,7 +89,11 @@ pub fn open_presentation(name: &str, bytes: &[u8]) -> Result<Presentation> {
|
||||
if lower.ends_with(".txt") || lower.ends_with(".md") {
|
||||
let text = String::from_utf8_lossy(bytes);
|
||||
let mut p = defaults::blank_presentation(defaults::WIDE, Default::default(), false);
|
||||
deckcraft_format::outline_to_slides(&mut p, &text);
|
||||
if lower.ends_with(".md") {
|
||||
deckcraft_format::markdown_to_slides(&mut p, &text);
|
||||
} else {
|
||||
deckcraft_format::outline_to_slides(&mut p, &text);
|
||||
}
|
||||
if p.slides.is_empty() {
|
||||
p = defaults::new_presentation(None);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,15 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
),
|
||||
cmd!("section.removeAll", "Remove All Sections", ["Home", "Slides", "Section"], None, "{}", has_slide, section_remove_all),
|
||||
cmd!("section.move", "Move Section", [], None, "{index, to}", has_slide, section_move),
|
||||
cmd!("slide.fromOutline", "Slides from Outline…", ["Insert", "Slides From"], None, "{text}", has_doc, from_outline),
|
||||
cmd!(
|
||||
"slide.fromOutline",
|
||||
"Slides from Outline…",
|
||||
["Insert", "Slides From"],
|
||||
None,
|
||||
"{text, markdown?: bool (headings are slides, list items bullets)}",
|
||||
has_doc,
|
||||
from_outline
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -584,10 +592,11 @@ fn section_move(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
fn from_outline(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let text = str_param(p, "text").unwrap_or("").to_string();
|
||||
let markdown = bool_param(p, "markdown").unwrap_or(false);
|
||||
s.edit(|doc, sel| {
|
||||
let before = doc.slides.len();
|
||||
let n = deckcraft_format::outline_to_slides(doc, &text);
|
||||
// outline_to_slides appends; move them after the current slide.
|
||||
let n = if markdown { deckcraft_format::markdown_to_slides(doc, &text) } else { deckcraft_format::outline_to_slides(doc, &text) };
|
||||
// both append; move them after the current slide.
|
||||
let at = (sel.slide + 1).min(before);
|
||||
let new: Vec<_> = doc.slides.drain(before..).collect();
|
||||
for (k, sl) in new.into_iter().enumerate() {
|
||||
|
||||
Reference in New Issue
Block a user