From e7eaf92e288350d058ad4c4b958fe45a9b7d6a8b Mon Sep 17 00:00:00 2001 From: Shaily Date: Feb 03 2018 00:07:19 +0000 Subject: [PATCH 1/3] Use markdown in hub description --- diff --git a/hubs/models/hub.py b/hubs/models/hub.py index 4cd13c4..0b8c34b 100644 --- a/hubs/models/hub.py +++ b/hubs/models/hub.py @@ -29,6 +29,7 @@ import flask 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.defaults import ( 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,11 @@ class Hub(ObjectAuthzMixin, BASE): "mtime": self.last_refreshed, "type": self.hub_type, } + 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 diff --git a/hubs/static/client/app/components/HubConfig/HubConfigPanelGeneral.js b/hubs/static/client/app/components/HubConfig/HubConfigPanelGeneral.js index 840aea1..8dc2d53 100644 --- a/hubs/static/client/app/components/HubConfig/HubConfigPanelGeneral.js +++ b/hubs/static/client/app/components/HubConfig/HubConfigPanelGeneral.js @@ -123,6 +123,7 @@ export default class GeneralPanel extends React.Component { 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 || ""} diff --git a/hubs/static/client/app/components/WidgetsArea.js b/hubs/static/client/app/components/WidgetsArea.js index 9b07545..7b531e3 100644 --- a/hubs/static/client/app/components/WidgetsArea.js +++ b/hubs/static/client/app/components/WidgetsArea.js @@ -44,7 +44,7 @@ class WidgetsArea extends React.PureComponent { { (this.props.hub.config.description && !this.props.editMode) &&
- {this.props.hub.config.description} +
} From 02eab106a5f0bc54493f5a4292366ae21f65f55b Mon Sep 17 00:00:00 2001 From: Shaily Date: Feb 03 2018 00:07:19 +0000 Subject: [PATCH 2/3] Changes after review --- diff --git a/hubs/models/hub.py b/hubs/models/hub.py index 0b8c34b..7514277 100644 --- a/hubs/models/hub.py +++ b/hubs/models/hub.py @@ -311,11 +311,12 @@ class Hub(ObjectAuthzMixin, BASE): "mtime": self.last_refreshed, "type": self.hub_type, } - result["description_md2html"] = { - '__html': clean_input.clean(markdown(result["config"]["description"], - extensions=['markdown.extensions.extra', - 'markdown.extensions.sane_lists'])) - } + 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 diff --git a/hubs/static/client/app/components/WidgetsArea.js b/hubs/static/client/app/components/WidgetsArea.js index 7b531e3..9b4eca5 100644 --- a/hubs/static/client/app/components/WidgetsArea.js +++ b/hubs/static/client/app/components/WidgetsArea.js @@ -44,7 +44,7 @@ class WidgetsArea extends React.PureComponent { { (this.props.hub.config.description && !this.props.editMode) &&
-
+
} From 0ebafa07c48f280154434c73ff5f80fe345f80b0 Mon Sep 17 00:00:00 2001 From: Shaily Date: Feb 03 2018 00:07:19 +0000 Subject: [PATCH 3/3] Add text to help --- diff --git a/hubs/static/client/app/components/HubConfig/HubConfigPanelGeneral.js b/hubs/static/client/app/components/HubConfig/HubConfigPanelGeneral.js index 8dc2d53..f97af47 100644 --- a/hubs/static/client/app/components/HubConfig/HubConfigPanelGeneral.js +++ b/hubs/static/client/app/components/HubConfig/HubConfigPanelGeneral.js @@ -134,7 +134,9 @@ export default class GeneralPanel extends React.Component { }

- +
+ Markdown syntax is supported.