support order,bullet with list

This commit is contained in:
appflowy 2021-09-16 09:30:51 +08:00
parent 2a42fd108c
commit 69c8eb09c5
4 changed files with 29 additions and 10 deletions

View File

@ -1,5 +1,6 @@
{
"svgviewer.enableautopreview": true,
"svgviewer.previewcolumn": "Active",
"svgviewer.showzoominout": true
"svgviewer.showzoominout": true,
"editor.wordWrapColumn": 120
}

View File

@ -1,6 +1,6 @@
#![allow(non_snake_case)]
use crate::{block_attribute, core::Attributes, ignore_attribute, inline_attribute};
use crate::{block_attribute, core::Attributes, ignore_attribute, inline_attribute, list_attribute};
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::{collections::HashSet, fmt, fmt::Formatter, iter::FromIterator};
@ -28,13 +28,19 @@ impl Attribute {
block_attribute!(Header, usize);
block_attribute!(Indent, usize);
block_attribute!(Align, String);
block_attribute!(List, String);
block_attribute!(List, &str);
block_attribute!(CodeBlock, bool);
block_attribute!(QuoteBlock, bool);
// ignore
ignore_attribute!(Width, usize);
ignore_attribute!(Height, usize);
// List extension
list_attribute!(Bullet, "bullet");
list_attribute!(Ordered, "ordered");
list_attribute!(Checked, "checked");
list_attribute!(UnChecked, "unchecked");
}
impl fmt::Display for Attribute {
@ -111,7 +117,7 @@ impl std::convert::From<usize> for AttributeValue {
}
impl std::convert::From<&str> for AttributeValue {
fn from(val: &str) -> Self { AttributeValue(Some(val.to_owned())) }
fn from(val: &str) -> Self { val.to_owned().into() }
}
impl std::convert::From<String> for AttributeValue {

View File

@ -18,7 +18,7 @@ macro_rules! inline_attribute {
macro_rules! block_attribute {
(
$key: ident,
$value: ident
$value: ty
) => {
pub fn $key(value: $value) -> Self {
Self {
@ -30,6 +30,22 @@ macro_rules! block_attribute {
};
}
#[macro_export]
macro_rules! list_attribute {
(
$key: ident,
$value: expr
) => {
pub fn $key(b: bool) -> Self {
let value = match b {
true => $value,
false => "",
};
Attribute::List(value)
}
};
}
#[macro_export]
macro_rules! ignore_attribute {
(

View File

@ -123,11 +123,7 @@ impl TestBuilder {
},
TestOp::Bullet(delta_i, iv, enable) => {
let document = &mut self.documents[*delta_i];
let value = match *enable {
true => "bullet",
false => "",
};
let attribute = Attribute::List(value.to_owned());
let attribute = Attribute::Bullet(*enable);
document.format(*iv, attribute).unwrap();
},
TestOp::Transform(delta_a_i, delta_b_i) => {