#546 Use markdown in hub description
Merged 4 years ago by abompard. Opened 4 years ago by shaily.
shaily/fedora-hubs 541  into  develop

file modified
+8
@@ -29,6 +29,7 @@ 

  import sqlalchemy as sa

  from sqlalchemy.orm import relation

  from sqlalchemy.orm.session import object_session

+ from markdown import markdown

  

  from hubs.authz import ObjectAuthzMixin, AccessLevel

  from hubs.database import BASE, Session
@@ -38,6 +39,7 @@ 

  from hubs.utils import username2avatar

  from hubs.utils.fedmsg import publish

  from hubs.signals import hub_created

+ from hubs.widgets import clean_input

  from .association import Association

  from .constants import ROLES, HUB_TYPES

  from .hubconfig import HubConfigProxy
@@ -309,6 +311,12 @@ 

              "mtime": self.last_refreshed,

              "type": self.hub_type,

          }

+         if result["config"]["description"]:

+             result["description_md2html"] = {

+                 '__html': clean_input.clean(markdown(result["config"]["description"],

+                                                      extensions=['markdown.extensions.extra',

+                                                                  'markdown.extensions.sane_lists']))

+             }

          for assoc in sorted(self.associations, key=lambda a: a.user.username):

              if assoc.role not in ROLES:

                  continue

@@ -123,6 +123,7 @@ 

              name="description"

              className={"form-control" + (invalid.description ? " is-invalid" : "")}

              id="hub-settings-general-description"

+             rows={10}

              disabled={stillLoading}

              onChange={this.handleChange}

              value={this.props.hubConfig.description || ""}
@@ -133,7 +134,9 @@ 

              </div>

            }

            <p className="form-text text-muted">

-             <FormattedMessage {...messages.description_help} />

+             <FormattedMessage {...messages.description_help} /> <br/>

+             <a href="https://daringfireball.net/projects/markdown/"

+                target="_blank" rel="noopener noreferrer">Markdown syntax</a> is supported.

            </p>

          </div>

          <div className="form-group row">

@@ -44,7 +44,7 @@ 

  

              { (this.props.hub.config.description && !this.props.editMode) &&

                <div className="alert alert-info hub-description">

-                 {this.props.hub.config.description}

+                 <div dangerouslySetInnerHTML={this.props.hub.description_md2html} style={{marginBottom: "-1em"}}></div>

                  <div className="hackybackground"></div>

                </div>

              }

This crashes if the description is unset (because it is None), please protect against that.

The conversion to markdown generates <p> tags which by default add a margin-bottom of 1em. As a result it looks a bit weird in the description, there's some white (or blue) space at the bottom. You can avoid this by setting style={{marginBottom: "-1em"}} on this element.

1 new commit added

  • Changes after review
4 years ago

rebased onto 8a8d664a8de7e5dc406ac2a1f3dcc91ea6777a8f

4 years ago

Almost perfect ! Please add in the help line below the config field the following:

<a href="https://daringfireball.net/projects/markdown/">Markdown syntax</a> is supported.

Otherwise people will only know by accident :-)

1 new commit added

  • Add text to help
4 years ago

rebased onto e7eaf92

4 years ago

Pull-Request has been merged by abompard

4 years ago