Skip to content

Commit f54ca5c

Browse files
committed
project_scrum: updated mermaid with web_mermaid
1 parent f794e5e commit f54ca5c

File tree

4 files changed

+4
-208
lines changed

4 files changed

+4
-208
lines changed

project_scrum/__manifest__.p.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@
110110
# # endif
111111
'sales_team',
112112
'calendar',
113-
# # if VERSION == "14.0"
114-
'web_widget_mermaid', # https://github.com/OCA/web/tree/14.0/web_widget_mermaid
115-
# # else
116-
'web_widget_mermaid_field' # https://github.com/VictorHachard/odoo-modules/tree/17.0/web_widget_mermaid_field,
117-
# # endif
113+
'web_mermaid'
118114
],
119115
'data': [
120116
'views/project_scrum_view.xml',

project_scrum/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
'mail', 'hr_timesheet',
104104
'sales_team',
105105
'calendar',
106-
'web_widget_mermaid_field' # https://github.com/VictorHachard/odoo-modules/tree/17.0/web_widget_mermaid_field,
106+
'web_mermaid'
107107
],
108108
'data': [
109109
'views/project_scrum_view.xml',

project_scrum/models/project_scrum_us.p.py

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111

1212
class ProjectUserStories(models.Model):
1313
_name = 'project.scrum.us'
14-
_inherit = ['mail.thread', 'mail.activity.mixin']
14+
_inherit = ['mail.thread', 'mail.activity.mixin', 'mermaid.mixin']
1515
_description = 'Project Scrum Use Stories'
1616
_order = 'sequence'
1717

18-
_mermaid_keywords = r"^(graph|sequenceDiagram|classDiagram|stateDiagram|" \
19-
r"erDiagram|flowchart|pie|journey|gantt|gitGraph)\b"
2018

2119
def create_test_case_from_us(self):
2220
active_ids = self.env['project.scrum.us'].browse(self.env.context.get('active_ids'))
@@ -174,100 +172,3 @@ def _read_group_sprint_id(self, present_ids, domain):
174172
'sprint_ids': _read_group_sprint_id,
175173
}
176174

177-
mermaid_editor = fields.Html(string="Editor", copy=False)
178-
179-
def wrap_mermaid_in_pre(self, mermaid_editor):
180-
"""
181-
Finds Mermaid diagrams in HTML content and wraps them inside <pre> tags.
182-
183-
Args:
184-
mermaid_editor (str): The raw HTML content.
185-
186-
Returns:
187-
str: Modified HTML with Mermaid diagrams wrapped in <pre>.
188-
"""
189-
if not mermaid_editor:
190-
return ""
191-
192-
soup = BeautifulSoup(mermaid_editor, "html.parser")
193-
194-
# Check for existing pre tags with mermaid content
195-
if soup.find('pre', class_='mermaid'):
196-
return str(soup)
197-
198-
# Find potential Mermaid blocks
199-
potential_blocks = [tag for tag in soup.find_all(["p", "div"])
200-
if re.search(self._mermaid_keywords, tag.get_text().lstrip(), re.MULTILINE)]
201-
202-
# Process each potential block
203-
for start_tag in potential_blocks:
204-
diagram_content = []
205-
siblings_to_remove = []
206-
current_tag = start_tag
207-
208-
# Process starting tag
209-
for child in BeautifulSoup(str(current_tag), "html.parser").find_all(string=True):
210-
if child.strip():
211-
diagram_content.append(html.unescape(str(child)))
212-
213-
# Process potential siblings
214-
next_tag = current_tag.next_sibling
215-
while next_tag and hasattr(next_tag, 'name') and next_tag.name in ['p', 'div']:
216-
if re.search(self._mermaid_keywords, next_tag.get_text().lstrip(), re.MULTILINE):
217-
break
218-
219-
for child in BeautifulSoup(str(next_tag), "html.parser").find_all(string=True):
220-
if child.strip():
221-
diagram_content.append(html.unescape(str(child)))
222-
223-
siblings_to_remove.append(next_tag)
224-
next_tag = next_tag.next_sibling
225-
226-
# Create pre tag and replace original tag
227-
pre_tag = soup.new_tag("pre")
228-
pre_tag.string = "\n".join(diagram_content)
229-
pre_tag['class'] = 'mermaid'
230-
start_tag.replace_with(pre_tag)
231-
232-
# Remove siblings that were processed
233-
for sibling in siblings_to_remove:
234-
sibling.extract() # extract() is an alternative to decompose()
235-
236-
return str(soup)
237-
238-
@api.depends('mermaid_editor')
239-
def _compute_mermaid_editor(self):
240-
"""
241-
Computes the Mermaid diagram text and wraps it in <pre> tags if needed.
242-
Only processes content that appears to be Mermaid diagrams.
243-
"""
244-
for rec in self:
245-
# Skip empty content or when called from our own update
246-
if not rec.mermaid_editor:
247-
rec.mermaid_diagram = ""
248-
continue
249-
250-
soup = BeautifulSoup(rec.mermaid_editor, "html.parser")
251-
252-
# Check for existing pre tag with mermaid content
253-
pre_tag = soup.find('pre', class_='mermaid')
254-
if pre_tag:
255-
rec.mermaid_diagram = pre_tag.get_text()
256-
continue
257-
258-
# Check if content appears to be mermaid format
259-
text_content = soup.get_text('\n', strip=True)
260-
if not re.search(self._mermaid_keywords, text_content, re.MULTILINE):
261-
rec.mermaid_diagram = ""
262-
continue
263-
264-
# Extract text preserving structure and indentation
265-
text_content = soup.get_text('\n', strip=False).replace('\xa0', ' ')
266-
rec.mermaid_diagram = text_content
267-
268-
# Wrap in pre tags
269-
wrapped_content = self.wrap_mermaid_in_pre(rec.mermaid_editor)
270-
if wrapped_content != rec.mermaid_editor:
271-
rec.mermaid_editor = wrapped_content
272-
273-
mermaid_diagram = fields.Text(string="Diagram", compute=_compute_mermaid_editor, copy=False)

project_scrum/models/project_scrum_us.py

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111

1212
class ProjectUserStories(models.Model):
1313
_name = 'project.scrum.us'
14-
_inherit = ['mail.thread', 'mail.activity.mixin']
14+
_inherit = ['mail.thread', 'mail.activity.mixin', 'mermaid.mixin']
1515
_description = 'Project Scrum Use Stories'
1616
_order = 'sequence'
1717

18-
_mermaid_keywords = r"^(graph|sequenceDiagram|classDiagram|stateDiagram|" \
19-
r"erDiagram|flowchart|pie|journey|gantt|gitGraph)\b"
20-
2118
def create_test_case_from_us(self):
2219
active_ids = self.env['project.scrum.us'].browse(self.env.context.get('active_ids'))
2320
if not active_ids:
@@ -161,101 +158,3 @@ def _read_group_sprint_id(self, present_ids, domain):
161158
_group_by_full = {
162159
'sprint_ids': _read_group_sprint_id,
163160
}
164-
165-
mermaid_editor = fields.Html(string="Editor", copy=False)
166-
167-
def wrap_mermaid_in_pre(self, mermaid_editor):
168-
"""
169-
Finds Mermaid diagrams in HTML content and wraps them inside <pre> tags.
170-
171-
Args:
172-
mermaid_editor (str): The raw HTML content.
173-
174-
Returns:
175-
str: Modified HTML with Mermaid diagrams wrapped in <pre>.
176-
"""
177-
if not mermaid_editor:
178-
return ""
179-
180-
soup = BeautifulSoup(mermaid_editor, "html.parser")
181-
182-
# Check for existing pre tags with mermaid content
183-
if soup.find('pre', class_='mermaid'):
184-
return str(soup)
185-
186-
# Find potential Mermaid blocks
187-
potential_blocks = [tag for tag in soup.find_all(["p", "div"])
188-
if re.search(self._mermaid_keywords, tag.get_text().lstrip(), re.MULTILINE)]
189-
190-
# Process each potential block
191-
for start_tag in potential_blocks:
192-
diagram_content = []
193-
siblings_to_remove = []
194-
current_tag = start_tag
195-
196-
# Process starting tag
197-
for child in BeautifulSoup(str(current_tag), "html.parser").find_all(string=True):
198-
if child.strip():
199-
diagram_content.append(html.unescape(str(child)))
200-
201-
# Process potential siblings
202-
next_tag = current_tag.next_sibling
203-
while next_tag and hasattr(next_tag, 'name') and next_tag.name in ['p', 'div']:
204-
if re.search(self._mermaid_keywords, next_tag.get_text().lstrip(), re.MULTILINE):
205-
break
206-
207-
for child in BeautifulSoup(str(next_tag), "html.parser").find_all(string=True):
208-
if child.strip():
209-
diagram_content.append(html.unescape(str(child)))
210-
211-
siblings_to_remove.append(next_tag)
212-
next_tag = next_tag.next_sibling
213-
214-
# Create pre tag and replace original tag
215-
pre_tag = soup.new_tag("pre")
216-
pre_tag.string = "\n".join(diagram_content)
217-
pre_tag['class'] = 'mermaid'
218-
start_tag.replace_with(pre_tag)
219-
220-
# Remove siblings that were processed
221-
for sibling in siblings_to_remove:
222-
sibling.extract() # extract() is an alternative to decompose()
223-
224-
return str(soup)
225-
226-
@api.depends('mermaid_editor')
227-
def _compute_mermaid_editor(self):
228-
"""
229-
Computes the Mermaid diagram text and wraps it in <pre> tags if needed.
230-
Only processes content that appears to be Mermaid diagrams.
231-
"""
232-
for rec in self:
233-
# Skip empty content or when called from our own update
234-
if not rec.mermaid_editor:
235-
rec.mermaid_diagram = ""
236-
continue
237-
238-
soup = BeautifulSoup(rec.mermaid_editor, "html.parser")
239-
240-
# Check for existing pre tag with mermaid content
241-
pre_tag = soup.find('pre', class_='mermaid')
242-
if pre_tag:
243-
rec.mermaid_diagram = pre_tag.get_text()
244-
continue
245-
246-
# Check if content appears to be mermaid format
247-
text_content = soup.get_text('\n', strip=True)
248-
if not re.search(self._mermaid_keywords, text_content, re.MULTILINE):
249-
rec.mermaid_diagram = ""
250-
continue
251-
252-
# Extract text preserving structure and indentation
253-
text_content = soup.get_text('\n', strip=False).replace('\xa0', ' ')
254-
rec.mermaid_diagram = text_content
255-
256-
# Wrap in pre tags
257-
wrapped_content = self.wrap_mermaid_in_pre(rec.mermaid_editor)
258-
if wrapped_content != rec.mermaid_editor:
259-
rec.mermaid_editor = wrapped_content
260-
261-
mermaid_diagram = fields.Text(string="Diagram", compute=_compute_mermaid_editor, copy=False)

0 commit comments

Comments
 (0)