Sanitizing urls to correct common user mistakes: not including the scheme ('http://' or 'https://') or pasting white spaces at the end or url, usually when they come from etherpads or mailing.

This closes ticket http://mutabit.com/repos.fossil/grafoscopio/tktview?name=c7fe88f9ca .
This commit is contained in:
Offray Vladimir Luna Cárdenas 2017-08-10 13:27:10 +00:00 committed by SantiagoBragagnolo
parent eaee95e051
commit 21117d4301
2 changed files with 32 additions and 31 deletions

View File

@ -288,6 +288,13 @@ GrafoscopioNode >> bodyAsMarkdownInto: aStream [
self embeddedNodes ifNotNil: [ aStream nextPutAll: (self embedNodes contents asString withInternetLineEndings); crlf; crlf].
]
{ #category : #operation }
GrafoscopioNode >> checksum [
"I return the SHA1SUM of the current tree. I'm used to test changes on the contents
and for traceability of how the document tree is converted to other formats, as markdown."
^ (SHA1 new hashMessage: self root flatten asSton) hex
]
{ #category : #accessing }
GrafoscopioNode >> children [
"Returns the receivers list of children"
@ -326,13 +333,6 @@ GrafoscopioNode >> copyToClipboard [
]
{ #category : #operation }
GrafoscopioNode >> cryptoSignature [
"I return the SHA1SUM of the current tree. I'm used to test changes on the contents
and for traceability of how the document tree is converted to other formats, as markdown."
^ (SHA1 new hashMessage: self root flatten asSton) hex
]
{ #category : #utility }
GrafoscopioNode >> deleteReferencesToRoot: aRootNode [
@ -735,7 +735,7 @@ GrafoscopioNode >> metadataAsYamlIn: markdownStream [
markdownStream
nextPutAll: '---';
lf;
nextPutAll: 'exportedFrom: ', self cryptoSignature;
nextPutAll: 'exportedFrom: ', self checksum;
lf.
self metadata
ifNotNil: [
@ -937,8 +937,10 @@ GrafoscopioNode >> tags [
ifTrue: [
migration := tags.
tags := OrderedCollection new.
tags add: migration ].
tags ifNil: [ tags := OrderedCollection new ].
self tagAs: migration ].
tags ifNil: [
tags := OrderedCollection new.
self tagAs: 'text' ].
^ tags
]

View File

@ -89,14 +89,8 @@ GrafoscopioNotebook >> body: anObject [
body := anObject
]
{ #category : #'editing nodes' }
GrafoscopioNotebook >> copyNodeToClipboard [
tree highlightedItem content copyToClipboard.
self notebookContent: notebook.
]
{ #category : #utilities }
GrafoscopioNotebook >> cryptoSignature [
GrafoscopioNotebook >> checksum [
"I return the cryptographic signature of the workingFile where this notebook is being stored.
I'm useful for data provenance and traceability of derivated files related with this source
notebook."
@ -105,6 +99,12 @@ GrafoscopioNotebook >> cryptoSignature [
^ (SHA1 new hashMessage: (self workingFile contents)) hex.
]
{ #category : #'editing nodes' }
GrafoscopioNotebook >> copyNodeToClipboard [
tree highlightedItem content copyToClipboard.
self notebookContent: notebook.
]
{ #category : #'editing nodes' }
GrafoscopioNotebook >> cutNodeToClipboard [
self copyNodeToClipboard; removeNode.
@ -275,9 +275,9 @@ GrafoscopioNotebook >> initializePresenter [
header whenTextChanged: [ :arg |
(tree highlightedItem content header) = arg
ifFalse: [
(tree highlightedItem) content header: arg.
tree highlightedItem content header: arg.
tree roots: tree roots]].
links whenTextChanged: [ :arg | tree highlightedItem content addLink: arg]
links whenTextChanged: [ :arg | tree highlightedItem content addLink: arg ]
]
{ #category : #initialization }
@ -475,13 +475,14 @@ GrafoscopioNotebook >> openFromFileSelector [
]
{ #category : #persistence }
GrafoscopioNotebook >> openFromUrl: anUrl [
GrafoscopioNotebook >> openFromUrl: url [
"Opens a tree from a file named aFileName"
| fileName |
fileName := (anUrl splitOn: '/') last.
GrafoscopioUtils
downloadingFrom: anUrl
| fileName sanitized |
sanitized := GrafoscopioUtils sanitize: url.
fileName := sanitized segments last.
GrafoscopioUtils
downloadingFrom: sanitized
withMessage: 'Downloading document...'
into: FileLocator temp.
self class new openFromFile: (FileLocator temp / fileName)
@ -570,18 +571,16 @@ GrafoscopioNotebook >> removeNode [
{ #category : #persistence }
GrafoscopioNotebook >> saveToFile: aFileReference [
"I save the current tree/document to a file"
"I save the current tree/document to a file."
aFileReference ifNil: [ self inform: 'No file selected for saving. Save NOT done'. ^ self ].
workingFile := aFileReference.
self workingFile exists ifTrue: [self workingFile delete].
self workingFile ensureCreateFile.
[ self exportAsSton: self notebook on: (self workingFile writeStream)]
ensure: [ (self workingFile writeStream) ifNotNil: #close ].
self workingFile ensureDelete.
self workingFile writeStreamDo: [:stream |
self exportAsSton: self notebook on:stream ].
self title: self workingFile basenameWithIndicator, ' | Grafoscopio notebook'.
self inform: ('File saved at: ', String cr, self workingFile fullName).
GrafoscopioDockingBar updateRecentNotebooksWith: aFileReference.
]
{ #category : #persistence }
@ -748,7 +747,7 @@ GrafoscopioNotebook >> topBar [
addItem: [ :item |
item
name: nil;
description: 'Reload link';
description: 'Import link content';
icon: #glamorousRefresh asIcon;
action: [ self importLinkContent ] ].
group