This commit is contained in:
Piotr 2024-07-24 10:15:18 +02:00 • committed by GitHub
commit e015480c01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 886 additions and 0 deletions

View file

@ -0,0 +1,11 @@
[package]
name = "markdown-widget"
version = "0.1.0"
edition = "2021"
[dependencies]
[dependencies.libcosmic]
path = "../../"
default-features = false
features = ["winit", "wgpu", "markdown"]

View file

@ -0,0 +1,105 @@
# Introduction to Markdown
Markdown is a lightweight markup language with plain text formatting syntax. Its design allows it to be converted to many output formats, but the original tool by the same name only supports HTML. Markdown is often used to format readme files, for writing messages in online discussion forums, and to create rich text using a plain text editor.
## Benefits of Markdown
Markdown offers several advantages:
1. **Simplicity**: Markdown's syntax is simple and easy to learn.
2. **Readability**: Even without formatting, Markdown documents are readable in plain text.
3. **Portability**: Being plain text, Markdown files can be opened and edited in any text editor.
4. **Flexibility**: It can be converted to various formats including HTML, PDF, and more.
## Basic Syntax
Here are some basic Markdown syntax elements:
- **Headings**: Use `#` for headings. More `#` characters indicate smaller headings.
- **Bold**: Use `**` or `__` for bold text. Example: `**bold text**`
- **Italic**: Use `*` or `_` for italic text. Example: `*italic text*`
- **Lists**: Use `-` or `*` for unordered lists and numbers for ordered lists.
### Links
My favorite search engine is [Duck Duck Go](https://duckduckgo.com "The best search engine for privacy") privacy search engine.
### Images
![The San Juan Mountains are beautiful!](/assets/images/san-juan-mountains.jpg "San Juan Mountains")
## Example
# Heading One
## Heading Two
### Heading Three
#### Heading Four
##### Heading Five
###### Heading Six
This is a paragraph with **bold text** and *italic text*.
> This is a block quote
- Item 1
- Item 2
- Item 3
1. First
2. Second
3. Third
# Example Markdown Document
This is a sample markdown document demonstrating how to include an embedded code snippet.
## Code Snippet
Below is an example of a simple Python function that adds two numbers:
```python
def add(a, b):
"""
This function takes two numbers and returns their sum.
Parameters:
a (int or float): The first number.
b (int or float): The second number.
Returns:
int or float: The sum of the two numbers.
"""
return a + b
# Example usage:
result = add(3, 5)
print(f"The sum of 3 and 5 is {result}")
```
## and this is rust
```rust
fn parse_span(span: Span) -> String {
let mut result = String::new();
match span {
markdown::Span::Break => result.push('\n'),
markdown::Span::Text(text) => result.push_str(&text),
markdown::Span::Code(code) => result.push_str(&code),
markdown::Span::Link(_, _, _) => {}
markdown::Span::Image(_, _, _) => {}
markdown::Span::Emphasis(emphasis) => {
for span in emphasis {
result.push_str(&parse_span(span));
}
}
markdown::Span::Strong(strong) => {
for span in strong {
result.push_str(&parse_span(span));
}
}
}
}```

View file

@ -0,0 +1,10 @@
mod window;
use cosmic::app::Settings;
use window::Window;
fn main() -> cosmic::iced::Result {
let settings = Settings::default();
cosmic::app::run::<Window>(settings, ())
}

View file

@ -0,0 +1,45 @@
use cosmic::{app::Core, widget, Application, Command};
#[derive(Debug, Clone)]
pub enum Message {}
pub struct Window {
core: Core,
markdown_text: String,
}
impl Application for Window {
type Executor = cosmic::executor::Default;
type Flags = ();
type Message = Message;
const APP_ID: &'static str = "io.github.elevenhsoft.Markdown";
fn core(&self) -> &Core {
&self.core
}
fn core_mut(&mut self) -> &mut Core {
&mut self.core
}
fn init(core: Core, _flags: Self::Flags) -> (Self, cosmic::app::Command<Self::Message>) {
let markdown_text = include_str!("../markdown.md").to_string();
(
Self {
core,
markdown_text,
},
Command::none(),
)
}
fn view(&self) -> cosmic::prelude::Element<Self::Message> {
let md = widget::text::markdown(&self.markdown_text);
widget::row().push(widget::scrollable(md)).into()
}
}