Convert markdown to HTML on demand

We were converting markdown to HTML every time we saved a record, which
has the same problems as sanitizing HTML before saving it to the
database, particularly because the body of a legislation draft is stored
in a translations table.

Performance-wise this isn't a problem: converting a text with more than
200_000 characters takes about a milisecond on my machine.

Note we need to modify a migration generated by globalize, since the
method `create_translation_table!` would fail now that we don't define
`translates :body_html` in the model.
This commit is contained in:
Javi Martín
2019-10-21 21:29:10 +02:00
parent 7bf4e4d611
commit 68ca29fa8b
7 changed files with 31 additions and 35 deletions

View File

@@ -66,7 +66,7 @@
data-legislation-annotatable-base-url="<%= legislation_process_draft_version_path(@process, @draft_version) %>"
data-legislation-open-phase="<%= @process.allegations_phase.open? %>">
<% end %>
<%= sanitize(@draft_version.body_html) %>
<%= sanitize(@draft_version.body_html, { attributes: ["id"] }) %>
</section>
</div>
</div>