SwiftUI - How to apply markdown to TextEditor? - swiftui

With iOS 15 and Swift 5, I can add markdown to text, e.g
Text("Regular")
Text("*Italics*")
Text("**Bold**")
Text("~Strikethrough~")
Text("`Code`")
Text("[Link](https://apple.com)")
Text("***[They](https://apple.com) ~are~ `combinable`***")
But is it possible to somehow apply this to TextEditor as well? Can a user highlight some written text and apply specific markdown format to that text?
TextEditor(text: $notes) // how can $notes accept markdown here?

Maybe do this:
Text(content).lineLimit(nil)

Related

how to text.append() a Hyperlink to TextEditor Swiftui

I have a TextEditor that i want to add a clickable Hyperlink using the TextEditor text.append()
TextEditor(text: $textE)
.textFieldStyle(.roundedBorder)
textE.append(contentsOf: "\n" + LINK......)
I believe you have to use markdown to achieve hyperlink in text.
Text("Hello! Example of a markdown with a link [example](https://example.com)")
This question may be useful for you about how to use uitextview

SwiftUI - How to make part of a Text Navigation Link in iOS 13?

I have Two Text views containing a bold part and a not bold part added by + operator in SwiftUI. Like Below:
Text(AppStrings.dummyName)
.bold()
+ Text(" \(AppStrings.dummyMemberRequest)")
I want to turn the Bold part into a NavigationLink. But it is not possible as + Operator only works with Text view.
How can I turn a part of the Text view into a NavigationLink in SwiftUI, iOS 13?
You can just use Markdown syntax instead of combining them like that
Text("This is a text with **bold** words")

How to use bold and normal text in same line in SwiftUI

I want to use multiple text formats in one Text view in SwiftUI. this would look like this:
i want to have multiple formats for text in the same text box at the same time even if it is really really really really really long text so it would need to wrap correctly. (and maybe even include links!)
I found this(How to bold text in TextField swiftUI?)  thread after a basic search, but it is not at all what I am looking for.
This would work similar to HTML's span
Here a simple example for you, with my example code you can code for iOS 13 or 14 as well:
struct ContentView: View {
var body: some View {
Text("Hello, World!") + Text(" Hello, World!").bold() + Text(" Hello, World!").italic()
}
}
output:
With iOS 15, you can use markdown for Text:
Text("i want to have multiple **formats** for text in the _same **text box**_ at the same time even if it is really _really_ **really _really_** ~~really~~ long text so it would need to wrap correctly. (and maybe even include [links](https://www.apple.com)!)")
Result:

Achieve letter-spacing in RaphaelJs

Is there a way to set letter-spacing in raphael js text? It can be done easily in CSS, how can I do it in raphael? Any hacks would also do..
Paper.print() has a letter-spacing attribute:
var txt = r.print(10, 50, "O HAI", r.getFont("Comic Sans"), 30, 'middle', 1).attr({fill: "#fff"});
^
this is the letter spacing
See the docs on that.
Note that this needs "cufon-style" font files to be included and will render a non-selectable path object instead of real text.
It can be done with normal css. take a look here : http://tutorials.jenkov.com/svg/text-element.html . The css is applied to svg too.
Here's a live demo that shows svg text with letter-spacing.

How to create a bold, red text label in Qt?

I want to write a single, bold red line in my application using Qt.
As far as I understand, I would create a QLabel, set its textFormat to rich text and give it a rich text string to display:
QLabel *warning = new QLabel;
warning->setTextFormat(Qt::RichText);
warning->setText("{\\rtf1\\ansi\\ansicpg1252 {\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;} {\\colortbl;\\red255\\green0\\blue0;} \\f0 \\cf0 this is bold red text}");
I tested this rich text string in a rich text editor and it displays fine.
But Qt displays the whole string with all braces, keywords and backslashes instead of "this is bold red text". What am I doing wrong?
Thank you for your help.
Try using HTML formatting: <b><font... etc </b>.
Qt Designer does it like this: <span style=" font-size:8pt; font-weight:600; color:#aa0000;">TextLabel</span>
You can use Qt StyleSheets and set the styleSheet property of QLabel
warning->setStyleSheet("font-weight: bold; color: red");
Qt supports most CSS styles on its QWidget-derived classes. You don't need to set the text format to Qt::RichText for this to work.
Qt uses a simple HTML subset for formatting.
You can also do it programmatically using the settext function. Something like this:
QString labelText = "<P><b><i><font color='#ff0000' font_size=4>";
labelText .append("Text what u want to display");
labelText .append("</font></i></b></P></br>");
QLabel label->setText(labelText);
You can do it in a single line as well.