Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mesonium
gajim
Commits
dbf44701
Commit
dbf44701
authored
2 years ago
by
Daniel Brötzmann
Browse files
Options
Downloads
Patches
Plain Diff
fix: CodeWidget: Don’t default to python for highlighting
Fixes #11012
parent
792a83bf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gajim/gtk/conversation/code_widget.py
+4
-10
4 additions, 10 deletions
gajim/gtk/conversation/code_widget.py
with
4 additions
and
10 deletions
gajim/gtk/conversation/code_widget.py
+
4
−
10
View file @
dbf44701
...
...
@@ -13,7 +13,6 @@
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from
typing
import
Any
from
typing
import
Tuple
from
typing
import
Optional
import
logging
...
...
@@ -72,16 +71,16 @@ def _on_copy(self, _button: Gtk.Button) -> None:
def
add_content
(
self
,
block
:
PreBlock
):
code
,
lang
=
self
.
_prepare_code
(
block
.
text
)
lang_name
=
self
.
_textview
.
set_language
(
lang
)
if
lang
is
None
:
self
.
_lang_label
.
set_text
(
_
(
'
Code snippet
'
))
else
:
lang_name
=
self
.
_textview
.
set_language
(
lang
)
self
.
_lang_label
.
set_text
(
_
(
'
Code snippet (%s)
'
)
%
lang_name
)
self
.
_textview
.
print_code
(
code
)
@staticmethod
def
_prepare_code
(
text
:
str
)
->
T
uple
[
str
,
Optional
[
str
]]:
def
_prepare_code
(
text
:
str
)
->
t
uple
[
str
,
Optional
[
str
]]:
text
=
text
.
strip
()
code_start
=
text
.
partition
(
'
\n
'
)[
0
]
lang
=
None
...
...
@@ -127,15 +126,10 @@ def _on_style_changed(self, *args: Any) -> None:
if
style_scheme
is
not
None
:
self
.
get_buffer
().
set_style_scheme
(
style_scheme
)
def
set_language
(
self
,
language_string
:
Optional
[
str
])
->
str
:
if
language_string
is
None
:
language_string
=
'
python3
'
def
set_language
(
self
,
language_string
:
str
)
->
str
:
lang
=
self
.
_source_manager
.
get_language
(
language_string
)
if
lang
is
None
:
lang
=
self
.
_source_manager
.
get_language
(
'
python3
'
)
assert
lang
is
not
None
return
_
(
'
Unknown language
'
)
log
.
debug
(
'
Code snippet lang: %s
'
,
lang
.
get_name
())
self
.
get_buffer
().
set_language
(
lang
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment