英文:
How to visualize formatted text without removing empty space?
问题
我想要可视化一个预格式化文本(使用YAML格式和缩进)。似乎<|{text}|>
Markdown模式和状态表示会从文本中移除缩进,即所有内容都会成为一个长串的文本。以下是一个示例输出。
version: '3.1' stories:
- story: 06a6e2c5e8bd4058b304b4f23d57aa80
steps:
- intent: bot_capabilities
user: What can you do
正确的格式应该是这样的:
version: '3.1'
stories:
- story: 06a6e2c5e8bd4058b304b4f23d57aa80
steps:
- intent: bot_capabilities
user: What can you do
是否有一种方法可以保留预格式化文本,特别是缩进?
我尚未找到适合“text”控件的合适属性。似乎“Raw”并不能解决这个问题。如果我在将其分配给状态变量之前打印字符串,输出格式是正确的。因此,我认为自动删除空格的问题发生在之后。
英文:
I want to visualize a pre-formatted text (with YAML format and indent). It seems that the <|{text}|> markdown pattern and the state representation removes intents from the text, i.e. all becomes a long mashed text. Here is an example output.
version: '3.1' stories: - story: 06a6e2c5e8bd4058b304b4f23d57aa80 steps: - intent: bot_capabilities user: What can you do
Correct is this:
version: '3.1'
stories:
- story: 06a6e2c5e8bd4058b304b4f23d57aa80
steps:
- intent: bot_capabilities
user: What can you do
Is there a way to keep preformatted text especially with indents?
I could not yet find a fitting property for the "text" control. Raw does not seem to solve the issue. If I print the string before assigning it to a state variable, the output format is correct. Therefore, I assume the stripping of empty space happens automatically afterwards.
答案1
得分: 0
最直接的方法是使用带有多行属性的输入可视元素。
main.py:
from taipy.gui import Gui
#with open("file.yaml", "r") as f:
# yaml_text = f.read()
yaml_text = """
version: '3.1'
stories:
- story: loferum ipsi
steps:
- intent: bot_capabilities
user: What can you do
"""
page = """
<|{yaml_text}|input|multiline|label=Input|>
<|{yaml_text}|input|multiline|not active|label=Inactive input|>
<|{yaml_text}|input|multiline|not active|label=Inactive white input|id=yaml|>
"""
Gui(page).run()
这是结果:
- 第一个输入可编辑
- 第二个不可编辑且灰色
- 第三个不可编辑且白色
对于最后一个元素,我添加了一些CSS以使不活跃的输入变为白色:
main.css:
#yaml.Mui-disabled{
color: white !important;
-webkit-text-fill-color: white !important;
}
已在GitHub上创建了一个问题,以直接改进文本可视元素。
英文:
The most straightforward way is to use an input visual element with multiline property turned on.
main.py:
from taipy.gui import Gui
#with open("file.yaml", "r") as f:
# yaml_text = f.read()
yaml_text = """
version: '3.1'
stories:
- story: loferum ipsi
steps:
- intent: bot_capabilities
user: What can you do
"""
page = """
<|{yaml_text}|input|multiline|label=Input|>
<|{yaml_text}|input|multiline|not active|label=Inactive input|>
<|{yaml_text}|input|multiline|not active|label=Inactive white input|id=yaml|>
"""
Gui(page).run()
Here is the result:
- The first input is editable
- The second is not editable and grey
- The third is not editable and white
For the last element, I added a bit of CSS to make the inactive input white:
main.css:
#yaml.Mui-disabled{
color: white !important;
-webkit-text-fill-color: white !important;
}
An issue has been created on GitHub to improve text visual elements directly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论