Skip to content

Commit

Permalink
encode and attach it to playground url
Browse files Browse the repository at this point in the history
  • Loading branch information
Guocork committed Sep 20, 2024
1 parent eacc554 commit 37a497d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ lipsum = "0.9"
rand = "0.8.5"

rfd = "0.14.1"
urlencoding = "2.1.3"


## Configuration for `cargo packager`
Expand Down
24 changes: 13 additions & 11 deletions src/chat/chat_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use makepad_widgets::markdown::MarkdownWidgetExt;
use makepad_widgets::*;

use makepad_markdown::parse_markdown;
use urlencoding::encode;

live_design! {
import makepad_widgets::base::*;
Expand Down Expand Up @@ -371,15 +372,14 @@ impl ChatLine {
}

if self.button(id!(link_button)).clicked(&actions) {
if self.code_block.contains("rust") {
let code_block = &self.code_block[4..];
} else if self.code_block.contains("rs"){
let code_block = &self.code_block[2..];
}
// 转化code成为encode
// let playground_url = &format!("https://play.rust-lang.org/?code={}", );
let encoded_code = encode(&self.code_block);

let playground_url = &format!(
"https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code={}",
encoded_code
);

if let Err(e) = robius_open::Uri::new("https://play.rust-lang.org").open() {
if let Err(e) = robius_open::Uri::new(playground_url).open() {
error!("Error opening URL: {:?}", e);
}
}
Expand Down Expand Up @@ -429,10 +429,12 @@ impl ChatLine {
if !latest_message.is_empty() {
// this mean its markdown
let code_block = extract_code_block(&latest_message);
if code_block.contains("rust") || code_block.contains("rs") {
if code_block.contains("rust") {
self.button(id!(link_button)).set_visible(true);
self.code_block = code_block[4..].to_owned();
} else if code_block.contains("rs") {
self.button(id!(link_button)).set_visible(true);
self.code_block = code_block.to_owned(); // to_string 还是 to_owned
log!("{}", self.code_block);
self.code_block = code_block[2..].to_owned();
}
}
}
Expand Down

0 comments on commit 37a497d

Please sign in to comment.