如何在不移除空白空间的情况下可视化格式化文本?

huangapple go评论55阅读模式
英文:

How to visualize formatted text without removing empty space?

问题

我想要可视化一个预格式化文本(使用YAML格式和缩进)。似乎<|{text}|> Markdown模式和状态表示会从文本中移除缩进,即所有内容都会成为一个长串的文本。以下是一个示例输出。

version: &#39;3.1&#39; stories:
- story: 06a6e2c5e8bd4058b304b4f23d57aa80
  steps:
  - intent: bot_capabilities
    user: What can you do

正确的格式应该是这样的:

version: &#39;3.1&#39;
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: &#39;3.1&#39; stories: - story: 06a6e2c5e8bd4058b304b4f23d57aa80 steps: - intent: bot_capabilities user: What can you do

Correct is this:

version: &#39;3.1&#39;
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(&quot;file.yaml&quot;, &quot;r&quot;) as f:
#    yaml_text = f.read()

yaml_text = &quot;&quot;&quot;
version: &#39;3.1&#39;
stories:
-   story: loferum ipsi
    steps:
    -   intent: bot_capabilities
        user: What can you do
&quot;&quot;&quot;

page = &quot;&quot;&quot;
&lt;|{yaml_text}|input|multiline|label=Input|&gt;

&lt;|{yaml_text}|input|multiline|not active|label=Inactive input|&gt;

&lt;|{yaml_text}|input|multiline|not active|label=Inactive white input|id=yaml|&gt;
&quot;&quot;&quot;

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.

huangapple
  • 本文由 发表于 2023年6月1日 20:18:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76381780.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定