Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to replace - [X] *
Qt 6.12 LTS is out! See what's new in the release blog

How to replace - [X] *

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 223 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote last edited by
    #1

    Markdown checkbox
    Mine:

    // s is a string line.
    if (s.startsWith("- [ ] "))
        s.replace("- [ ] ", "<input type=\"checkbox\">");
    
    if (s.startsWith("- [x] "))
        s.replace("- [x] ", "<input type=\"checkbox\" checked>");
    
    if (s.startsWith("- [X] "))
        s.replace("- [X] ", "<input type=\"checkbox\" checked>");
    

    Target:

    // * means strings, add \n at line end
    if (s.startsWith("- [ ] "))
        s.replace("- [ ] *", "<input type=\"checkbox\">*\n");
    
    if (s.startsWith("- [x] "))
        s.replace("- [x] *", "<input type=\"checkbox\" checked>*\n");
    
    if (s.startsWith("- [X] "))
        s.replace("- [X] *", "<input type=\"checkbox\" checked>*\n");
    

    https://github.com/sonichy

    JonBJ 1 Reply Last reply
    0
    • sonichyS sonichy

      Markdown checkbox
      Mine:

      // s is a string line.
      if (s.startsWith("- [ ] "))
          s.replace("- [ ] ", "<input type=\"checkbox\">");
      
      if (s.startsWith("- [x] "))
          s.replace("- [x] ", "<input type=\"checkbox\" checked>");
      
      if (s.startsWith("- [X] "))
          s.replace("- [X] ", "<input type=\"checkbox\" checked>");
      

      Target:

      // * means strings, add \n at line end
      if (s.startsWith("- [ ] "))
          s.replace("- [ ] *", "<input type=\"checkbox\">*\n");
      
      if (s.startsWith("- [x] "))
          s.replace("- [x] *", "<input type=\"checkbox\" checked>*\n");
      
      if (s.startsWith("- [X] "))
          s.replace("- [X] *", "<input type=\"checkbox\" checked>*\n");
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote last edited by JonB
      #2

      @sonichy
      We could do this in a couple of ways:

      if (s.startsWith("- [ ] ")) {
          s.replace("- [ ] ", "<input type=\"checkbox\">");
          s.append("\n");
      }
      

      or

      s.replace(QRegularExpression("^- \\[ \\] (.*)$"), "<input type=\"checkbox\">\\1\n");
      

      However, I suspect putting in a \n newline will not do what you want. Per your other post and the linked picture there I think you want these "items" on separate lines. Remember that in HTML \n is just the same as any other whitespace character so it will just producer a space and stay on same line. You probably want either to insert a line break, HTML <br>, or possibly put your items into some kind of HTML list (like <dl> <dt>).

      1 Reply Last reply
      2
      • sonichyS Offline
        sonichyS Offline
        sonichy
        wrote last edited by
        #3

        Way 1 is more easy.

        https://github.com/sonichy

        1 Reply Last reply
        0
        • sonichyS sonichy has marked this topic as solved

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved