Skip to content

Commit

Permalink
Update quick scrape view markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrankriyam committed Nov 5, 2024
1 parent 36cb86d commit 3552aba
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"location" : "https://github.com/rryam/AgniKit",
"state" : {
"branch" : "main",
"revision" : "17559d0417e78b44f37acc081047a170bf028585"
"revision" : "36cb86d37fdc9ecb2d5558ae39467e78b0f82cd2"
}
}
],
Expand Down
10 changes: 6 additions & 4 deletions Agni/Agni/Agni.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
34 changes: 34 additions & 0 deletions Agni/Agni/Components/MarkdownView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import SwiftUI

/// A view that renders basic Markdown content using SwiftUI Text.
///
/// `MarkdownView` provides a lightweight way to display formatted Markdown text
/// using SwiftUI's built-in AttributedString markdown parsing.
///
/// ## Usage
/// ```swift
/// MarkdownView("# Hello\nThis is **bold** and *italic* text")
/// ```
struct MarkdownView: View {
/// The formatted content to be displayed
private let content: AttributedString

/// Creates a new MarkdownView with the specified content.
///
/// - Parameter content: A string containing Markdown-formatted text
init(_ content: String) {
do {
self.content = try AttributedString(markdown: content)
} catch {
print("Error parsing markdown: \(error)")
self.content = AttributedString(content)
}
}

var body: some View {
Text(content)
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
}
}
2 changes: 1 addition & 1 deletion Agni/Agni/Components/ResultView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ResultView: View {

ScrollView {
if selectedFormat == "markdown" {
// MarkdownView(content)
MarkdownView(content)
} else {
TextEditor(text: .constant(content))
.font(.system(.body, design: .monospaced))
Expand Down
29 changes: 28 additions & 1 deletion Agni/Agni/Views/QuickScrapeView.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import AgniKit

struct QuickScrapeView: View {
@State private var url = ""
Expand All @@ -10,6 +11,32 @@ struct QuickScrapeView: View {
@State private var waitTime: Double = 0
@State private var timeout: Double = 30

private let agni = AgniKit(apiKey: "fc")

private func performScrape() async {
do {
let includeTagsArray = includeTags.isEmpty ? nil :
includeTags.split(separator: ",").map(String.init)
let excludeTagsArray = excludeTags.isEmpty ? nil :
excludeTags.split(separator: ",").map(String.init)

let response = try await agni.scrape(
url: url,
formats: formats,
onlyMainContent: onlyMainContent,
includeTags: includeTagsArray,
excludeTags: excludeTagsArray,
waitFor: Int(waitTime * 1000),
timeout: Int(timeout * 1000)
)

result = response.data.markdown ?? "No markdown content available"

} catch {
result = "Error: \(error.localizedDescription)"
}
}

var body: some View {
Form {
Section("Input") {
Expand All @@ -34,7 +61,7 @@ struct QuickScrapeView: View {
Section("Actions") {
Button("Scrape") {
Task {
// await performScrape()
await performScrape()
}
}
}
Expand Down

0 comments on commit 3552aba

Please sign in to comment.