Skip to content

Commit

Permalink
fix: special characters and camel casing no longer break definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
becdavid committed Jul 5, 2024
1 parent d67deaa commit 95661b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions keyterms/keyterms.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ def update_keyterm_html(self, list, course_id):
self.keytermhtml = ""
for keyterm in list:
div_parent_id = "#allKeytermsList"
keyterm_card_header_id = pydash.camel_case("heading" + keyterm)
keyterm_data_target = pydash.camel_case("collapse" + keyterm)
# remove all non alphanumeric characters and capitalize each word in keyterm. This matches what is being done in keyterms.js
clean_keyterm = ''.join(char for char in keyterm.title() if char.isalnum())
keyterm_card_header_id = pydash.camel_case("heading" + clean_keyterm)
keyterm_data_target = pydash.camel_case("collapse" + clean_keyterm)
keyterm_data_target_hashed = f'#{keyterm_data_target}'
keyterm_show = ("show" if list[0] == keyterm else "")
cardItem = '<div class="card">\n'
Expand All @@ -162,7 +164,7 @@ def update_keyterm_html(self, list, course_id):
cardItem += ' </div>\n'
cardItem += ' <div id="{keyterm_data_target}" class="collapse {keyterm_show}" aria-labelledby="{keyterm_card_header_id}" data-parent="{div_parent_id}">\n'
cardItem += ' <div class="{keyterm_data_target} card-body">\n'
cardItem += ' Example Content.\n'
cardItem += ' Error loading content.\n'
cardItem += ' </div>\n'
cardItem += ' </div>\n'
cardItem += '</div>\n'
Expand Down
4 changes: 3 additions & 1 deletion keyterms/static/js/src/keyterms.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
function camelize(str) {
return str.toLowerCase()
// Replaces any - or _ characters with a space
.replace(/[-_]+/g, ' ')
.replace(/[-_/]+/g, ' ')
// Removes any non alphanumeric characters
.replace(/[^\w\s]/g, '')
// Ensure there are no double spaces after removing characters
.replace(/ /g, ' ')
// Uppercases the first character in each group immediately following a space
// (delimited by spaces)
.replace(/ (.)/g, function($1) { return $1.toUpperCase(); })
Expand Down

0 comments on commit 95661b4

Please sign in to comment.